Re: Xcode 4 auto-importing Objective C categories from static library
Re: Xcode 4 auto-importing Objective C categories from static library
- Subject: Re: Xcode 4 auto-importing Objective C categories from static library
- From: "Bradley S. O'Hearne" <email@hidden>
- Date: Sat, 23 Apr 2011 15:57:37 -0700
Thanks for the response, Stephen. I was under the impression that category modification was limited to the types within which they are imported. Thanks for expanding my knowledge of categories!
Cheers,
Brad
On Apr 23, 2011, at 3:22 PM, Stephen J. Butler wrote:
> On Sat, Apr 23, 2011 at 3:36 PM, Bradley S. O'Hearne
> <email@hidden> wrote:
>> Since transitioning to Xcode 4, I have discovered a very curious shift in the way Objective C categories are handled in static libraries. In general, if you create an Objective C category, you have to import that category into an implementation (.m) class in order for that category's additions to be visible and used. That worked great in Xcode 3, as you can control what categories methods appear wherever by merits of using the import (or not). However, in Xcode 4, all categories defined in a static library used in a dependent project are by definition visible, even if not imported.
>
> It's always been this way at runtime. When a category is loaded it
> changes the behavior of all instances of a class that it modifies, no
> ifs/ands/buts. It's loaded by the DYLD, and that has no concept of
> your imports/includes. From the Obj-C docs:
>
> ""Category methods can do anything that methods defined in the class
> proper can do. At runtime, there’s no difference. The methods the
> category adds to the class are inherited by all the class’s
> subclasses, just like other methods.""
>
> Now the tools, on the other hand, were less smart in Xcode3 and below.
> Autocomplete, IB message browser, etc only knew about the
> messages/properties visible to the immediate code block (via import,
> include, etc). That Apple has fixed this in Xcode 4 to better match
> reality is a GOOD THING.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden