Interface Builder is not able to find classes in a static library - objective-c

Interface Builder is not able to find classes in a static library. It is throwing Unknown MyClassName in Interface Builder error when I run the application. Please note that I am using this class in the controller but still seeing this behavior in Xcode 4.6+.
This solution works but I can't add 30+ categories for as many classes in the static library. It looks uglier when you have multiple static libraries: Xcode 4, Interface Builder and the Awareness of Classes in a Static Library
The best one I've been able to find so far is to add [MyClassName class]; calls in my main method for each one of the static library classes to force Xcode to load them but again it requires all those "class" statements in the main which I am trying to avoid.
Adding "all_load" to linker flag works too but causes tons of files getting included in the build.
Just wondering if anybody knows of a better and cleaner way to deal with this mess?

Related

Warnings while using a plugin and static library in a cocoa project

I have a scenario where I need to use a plugin as well as a static library into my xcode project. The plugin will be dynamically loaded into the system. Now, the static library is also getting used in creation of the plugin.
While executing my project I am getting a warning saying :
Class A is getting referenced from /staticLibraryPath and plugin. One of them will be used.
Please let me know, how to resolve the warning or a better way of implementing the scenario.
The issue is a name class of the two ClassA types found in both plugin and library
I assume you have control over the source of either plugin / library.
.. rename Class A in one instance to make the names not clash -- I don't think there is another way to get rid of the warning/error

Selectively loading classes in Objective-C

I have modules but no source code from two different people which both include the same class. Is there any way to selectively load classes out of the modules so that the duplicated class doesn't collide?
Yes I am aware of this alternate solution which suggests loading and unloading and would rather do it by selectively loading classes and being done with it. What is the best way to solve an Objective-C namespace collision?
If the code is written into a .framework, you could possibly load using something like #import <myFramework/MFMyCode.h>. There's no way to selectively load a class in objective-c for iDevices, if you're on the Mac, you can use the method linked in your question.
I ran across this problem where I wanted to conditionally load a class from a project if that project existed, and to not load it if it did not. Unfortunately, there's no real way to resolve this problem since imports are all done at compile time.

isMemberOfClass with static library linked twice

I'm working on few plugins for Quartz Composer, that all link to the same custom static library copied for each of them in the bundles frameworks folder. The plugins could be used separately, so I have to distribute the library in each plugin.
Everything goes well, apart from the isMemberOfClass and isKindOfClass methods. I read here that importing twice the same classes could be the origin of the problem.
I have no error at compilation.
Let's say that I have 2 plugins (NSBundles) that contains the lib XCode project and compile it before linking to it.
They both copy the lib in their resources folder.
Then, they both instantiate a custom hOzPolygon2D class from that library.
The first plugin return true to the test of the hOzPolygon2D object with isMemberOfClass method.
The second return false.
isKindOfCLass method returns the same "error".
I can't imagine a solution in my case. I'm really not a compilation professional and would really appreciate some help.
You should distribute the static library separately (possibly as its own framework). From the question title I assume you're seeing duplicate symbol errors from the linker. If you statically link the same static library into multiple other libraries and then try to link an application to more than one of those libraries you're bound to see these duplicate symbol issues. I haven't actually tried this with frameworks, but I know of this issue from linking iOS apps against interdependent static libraries.
You shouldn't worry about the fact that the modules can be used separately. Just make sure your users can also get the base library. This is a normal situation. For example AppKit and UIKit depend on Foundation, but neither of them actually contains a copy of Foundation.

How to make sure my reusable static library doesn't force my project to include multiple frameworks?

I try to put some reusable functions into my own static library but i noticed one problem.
Let's say the static library has many functions and some requires quartz core framework, some requires messgeUI etc.
When I build a new project, I include this static library project into my code so that I can reuse those functions.
Now even if I only use a simple function that doesn't require any frameworks, I am forced to include all the quartzcore, message UI frameworks or I will face build errors because the static library requires them- but I do not need all of them!
How can I design a better general purpose static library that doesn't force people to include frameworks that is not used by them at all?
You can use weak linking - if weak linkage is used, unused symbols (functions, methods, global variables) don't have to be present at linking time.

C# style class extension in objective-c

I'm just learning objective-c after a fair amount of experience with C#. One of the things I sorely miss is the ability to write extension methods in a separate project that I could reference in all of my projects. Here's some naive c#:
public static bool IsShortString(this string s) {
return s.length <= 3;
}
In Visual Studio, I could just add a reference, an using, and bam myString.IsShortString() would be a, rather useless, method.
So I think I want to write a static library, but I'm not sure where I'm going from there.
One additional question, if I do write this static library, will I be able to use all of the methods throughout various files in the library using one #import directive, or will I have to import each header individually?
What you are looking for is called Category, and it allows you to add some additional methods to existing classes. Check the reference http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html
You can create your own toolkit which is a static library containing categories you made. Common practice is to create one header file containing imports for all the headers in the lib, so when using it, you just do
#import "libName.h"
Also, when creating a static library containing categories it is important to include -all_load and -ObjC linker flags to your project.
The closest thing in objective-c is categories.
This is also a good tutorial on categories.