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. 

Here's an example. I have a common static library I have created to hold a lot 
of my frequently-used utility code, and commonly used categories. One such 
category in my static library is called UIViewController+Utils. If I create a 
brand new Xcode project (I used the iOS Tab Bar Application template), and add 
the static library to the project using the menu just so that it shows in the 
project, all of the view controllers in that template project are inheriting 
the view controller behavior from the category. I have not added *any* import 
statements or touched one line of code in that new project. I can visually see 
that these category methods from my UIViewController+Utils category in my 
static library because if I pull up the MainWindow.xib file, and click on the 
TabBarController object, I can see some actions defined by my category in the 
Connections Inspector. Also, any methods overridden by the category will 
exhibit the category's behavior in any base class (in other words, all view 
controllers will be by default effected by UIViewController categories, even 
though they don't import those categories). 

This is no bueno. I do not want all of my static library's categories to be 
used regardless of whether an import statement exists or not. Unless there is 
something obvious I am missing here, this would seem to call into question any 
use of categories in static libraries, and I have a major code refactoring 
required to reorganize how code is shared between projects. 

Can anyone shed some light on this? Why would UIViewControllers bear the 
effects of a UIViewController category in a static library if no import 
statements for that category or any other class which imports it anywhere in 
the project? 

Thanks.

Brad
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to