<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Mon, 17 Aug 2026 10:37:45 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>ajay babu - 2015-04-07 11:23:56</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>how to call the description method on the class instance</description><guid isPermaLink="true">c6622714b2f2ecd209f9f9fe34b729a0</guid><pubDate>Tue, 07 Apr 2015 11:23:56 GMT</pubDate></item><item><title>Preston - 2012-06-08 00:56:38</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>You can use NSGetSizeAndAlignment() to get those values when adding an ivar.</description><guid isPermaLink="true">6dd3392acef3bce9d562e3a28f4c974e</guid><pubDate>Fri, 08 Jun 2012 00:56:38 GMT</pubDate></item><item><title>Whisper - 2012-01-04 13:46:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Great article, thanks.
&lt;br /&gt;
&lt;br /&gt;A little typo there near the end of this line:
&lt;br /&gt;
&lt;br /&gt;object_getInstanceVariable(obj, "foo", &amp;amp;currentValue;);</description><guid isPermaLink="true">5c5143488502c8eb6f1ddae8e950f462</guid><pubDate>Wed, 04 Jan 2012 13:46:21 GMT</pubDate></item><item><title>Kevin L - 2011-10-25 16:49:19</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Mike, sorry about the double post about ARC, didn't see your response until after I posted.</description><guid isPermaLink="true">016bf4850a93ef6ce98f536a9357fc1c</guid><pubDate>Tue, 25 Oct 2011 16:49:19 GMT</pubDate></item><item><title>Kevin L - 2011-10-25 16:47:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Apparently it is a bug that objc_allocateClassPair doesn't work in iOS 5 with ARC enabled.  The workaround is to use the compiler flag -fno-objc-arc on the file using the objc_allocateClassPair method and it will work fine.</description><guid isPermaLink="true">a02d5fe390891861e2ae87e273abc60c</guid><pubDate>Tue, 25 Oct 2011 16:47:53 GMT</pubDate></item><item><title>mikeash - 2011-10-25 14:46:25</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Mr. Wight was using ARC, and I assume you are as well. It's not currently possible to safely call objc_allocateClassPair with ARC. Move your relevant code into a separate file and disable ARC for that file, and all should be well.</description><guid isPermaLink="true">427b27fe894c3b6dca4863a60a5791ed</guid><pubDate>Tue, 25 Oct 2011 14:46:25 GMT</pubDate></item><item><title>Kevin L - 2011-10-25 14:41:34</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>I'm running into the same issue with objc_allocateClassPair on both the simulator and device.  Is there an alternative to using objc_allocateClassPair or a way of getting it working?</description><guid isPermaLink="true">b21b82b9e6ec7aba30b6df609c05aaa2</guid><pubDate>Tue, 25 Oct 2011 14:41:34 GMT</pubDate></item><item><title>Jonathan Wight - 2011-10-18 22:23:31</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>As of iOS 5, on the simulator Class mySubclass = objc_allocateClassPair([NSObject class], "MySubclass", 0); will cause an EXC_BAD_ACCESS exception...</description><guid isPermaLink="true">30aeccb2d233c4fc3ca11234386e88d4</guid><pubDate>Tue, 18 Oct 2011 22:23:31 GMT</pubDate></item><item><title>mikeash - 2010-11-26 22:03:03</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>It's best to ignore the formal definition of &lt;code&gt;IMP&lt;/code&gt; and just think of it as being a generic method implementation pointer, kind of like a &lt;code&gt;void *&lt;/code&gt; for methods. Just like you can't access the contents of a &lt;code&gt;void *&lt;/code&gt; without casting it to a more specific type, so you shouldn't use an &lt;code&gt;IMP&lt;/code&gt; without casting it to a more specific type.
&lt;br /&gt;
&lt;br /&gt;To put it another way, compatibility with the declared type of &lt;code&gt;IMP&lt;/code&gt; doesn't matter. What does matter is compatibility with the code that will be generated at the call site to the method, which is determined by the method declaration that you're trying to match.</description><guid isPermaLink="true">d069b4ff2b293c45baff607456354d9f</guid><pubDate>Fri, 26 Nov 2010 22:03:03 GMT</pubDate></item><item><title>Ling - 2010-11-26 00:58:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>One thing I'm curious about:
&lt;br /&gt;The return type of CountOfObject is NSUInteger which is not compatible with id, then why could it be safely cast to IMP?</description><guid isPermaLink="true">fa4f0aa1b3b3314754d915a20060f8f4</guid><pubDate>Fri, 26 Nov 2010 00:58:15 GMT</pubDate></item><item><title>Kyle S - 2010-11-06 22:40:30</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Jason, that sounds like an excellent feature request to make for clang/LLVM.</description><guid isPermaLink="true">5bb92d3353b66c808f8f84488e19bcc0</guid><pubDate>Sat, 06 Nov 2010 22:40:30 GMT</pubDate></item><item><title>mikeash - 2010-11-06 18:05:44</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>&lt;b&gt;Jason:&lt;/b&gt; Indeed, I have rued and lamented that many times.</description><guid isPermaLink="true">c3998d296843037ef82bb58a8a809ca9</guid><pubDate>Sat, 06 Nov 2010 18:05:44 GMT</pubDate></item><item><title>Jason - 2010-11-06 16:15:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>It's a shame the compiler doesn't emit @encode(...) as literal strings, so you could just say:
&lt;br /&gt;
&lt;br /&gt;const char * x = @encode(NSUInteger) @encode(id) @encode(SEL) @encode(id);
&lt;br /&gt;
&lt;br /&gt;Great article, and thanks for MAObjCRuntime!</description><guid isPermaLink="true">fe90e8b406c2091afe1d82698fd034b5</guid><pubDate>Sat, 06 Nov 2010 16:15:26 GMT</pubDate></item><item><title>Brandon Walkin - 2010-11-06 10:24:35</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Great article. Looking forward to part two.</description><guid isPermaLink="true">7ba4de3f5b1bfa6032aebadede1feb6e</guid><pubDate>Sat, 06 Nov 2010 10:24:35 GMT</pubDate></item><item><title>Nick - 2010-11-05 20:58:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Another really interesting article, thanks :-)</description><guid isPermaLink="true">5ee687afc2fb6c40c224be2477c8bad2</guid><pubDate>Fri, 05 Nov 2010 20:58:12 GMT</pubDate></item><item><title>mikeash - 2010-11-05 18:04:11</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Good catch, and fixed.</description><guid isPermaLink="true">d4a912cea48d8f68e6260c6b7e505d0e</guid><pubDate>Fri, 05 Nov 2010 18:04:11 GMT</pubDate></item><item><title>Jesper - 2010-11-05 17:36:31</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html#comments</link><description>Nice article. The &lt;code&gt;objc_allocateClassPair&lt;/code&gt; example should use a C string, not an NSString.</description><guid isPermaLink="true">4d0d27dee643ab6ed716a9032999345c</guid><pubDate>Fri, 05 Nov 2010 17:36:31 GMT</pubDate></item></channel></rss>
