Warnings while using a plugin and static library in a cocoa project - objective-c

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

Related

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

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?

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.

Save and Load instances of objects created earlier via the Eclipse registry

I am currently experiencing a problem in my RCP application and wanted to ask, if someone stumbled over the same problem and can give me some valuable hints:
My RCP application allows plugins to provide implementations of a specific abstract class of my model (singleton) to extend my model during runtime via the update manager. I instantiate these classes via
extensionPointImplementation.createExecutableExtension(..)
after parsing the Eclipse registry. I can serialize the created instances using the default Java serialization API.
Now to the problem: The plugin trying to deserialize the objects cannot find the class implementations of the model extensions due to the fact, that there is no plugin dependency between the plugins. Nevertheless, it is not possible for me to create such a dependency which would make the idea of extending the model during runtime obsolete.
Is it possible to solve this problem by using the default Java serialization API or do I have to implement my own serialization (which parses the Eclipse registry and creates the instances via the line shown above if all necessary plugins are available, otherwise throw an exception) which might be based on the default Java serialization API (if possible I do not want to create the serialization completely by myself)?
Thanks.
You need to define a so called buddy policy.
In the bundle trying to instantiate the class add
Eclipse-BuddyPolicy: registered
to the manifest.mf.
In the bundle providing the class add
Eclipse-RegisterBuddy: <symbolic name of the bundle instantiating the class>
to the manifest.mf.

Class Foo is implemented in both MyApp and MyAppTestCase. One of the two will be used. Which one is undefined

Recently I started Unit testing my application. This project (in Xcode4) was created without a unit test bundle so I had to set it up.
I have followed the steps from here: http://cocoawithlove.com/2009/12/sample-mac-application-with-complete.html
And It was working well for simple classes but now I am trying to test a class that depends on another and that on another, etc.
First I got a linker error so I added *.m files to the test case target but now I get a warning for every class I am trying to test:
Class Foo is implemented in both MyApp
and MyAppTestCase. One of the two will
be used. Which one is undefined.
I wonder why is that? How can I solve this? Maybe I missed something when setting the unit test target?
Edit - The Solution
Set "Bundle Loader" correctly to $(BUILT_PRODUCTS_DIR)/AppName.app/AppName
Set "Symbols Hidden by Default" to NO (in Build Settings of the target application). This is where the linker errors come from because it is YES by default!. I've been struggling with this for so long!.
Source: Linking error for unit testing with XCode 4?
Class Foo is implemented in both MyApp and MyAppTestCase. One of the two will be used. Which one is undefined.
I wonder why is that?
because both images (the app and the unit test bundle) define the implementation of the class. the class is dynamically loaded into the objc runtime. the objc runtime uses a flat namespace. how this works:
the binary is loaded, starting with its dependencies
as each binary is loaded, the objc classes register with the objc runtime
if a class with a specific name is loaded twice, the behaviour is undefined. one implementation of a class (with identical names) can be loaded into the objc runtime.
the typical problem here is that you will be returned one implementation - your app will likely crash when the type conflicts (when the class does not come from the same source file).
you typically avoid this by either renaming a class, or export the class in one image. renaming the class obviously does not apply to your case. you have one file Foo.m which is being compiled, exported, and loaded by two images when it should be in one.
this should be interpreted by you as a duplicate symbol linker error. even though the implementation is the same source file (and the implementation is the same) - this a problem that you must fix.
How can I solve this?
if Foo.m is a class of the app, you have to remove (do not compile and link) Foo.m from the unit test. if it's part of the unit test, then do not compile and link it into the unit test target.
then, follow the instructions in the post for linking/loading your unit test to the app. it's in this general area of the post: where "WhereIsMyMac" is the name of the application you're unit testing. This will let the testing target link against the application (so you don't get linker errors when compiling). the important part is that your test files are compiled in the unit test target (only), and your app's classes are compiled and linked into the app. you can't just add them - they link and load dynamically.
Maybe I missed something when setting the unit test target?
From the article you linked:
Note: The testing target is a separate target. This means that you need to be careful of target membership. All application source files should be added to the application target only. Test code files should be added to the testing target only.
the part that you got wrong is probably the link and load phases of the unit test bundle.
If you are using Cocoapods, your podfile only needs the dependencies in the section for the main target, not the test targets. If you do add duplicate dependencies for the test targets, you'll get the OP's error message.
target 'MyProject' do
pod 'Parse'
end
target 'MyProjectTests' do
end
target 'MyProjectUITests' do
end
For me, all I needed to do was uncheck the checkbox that makes the Foo class a member of the unit test target. It should not be a member of both targets, and should look like this:
In case you can't see the image, it's a screenshot of the Xcode "Target Membership" pane. There are two targets: one with an "A" application icon and the test name. The other is the unit test target, and has a unit test icon:
Target Membership
[X] Foo
[ ] FooTests
For me this happened because I deployed to the device and then to the simulator as I have NSZombies enabled. The solution was to switch to the simulator configuration & do a Product -> Clean then switch to the device configuration & do the same. Error went away. It's to do with build cache.
The reason is that you override RUNPATH_SEARCH_PATHS of your App Target`s build setting defined in other target.
Solution:
Go to your App Target and find RUNPATH_SEARCH_PATHS build setting and use there $(inherited) flag for both: Debug and Release
Come across the same issues, My situation is Class NSNotification is implemented in both /System/Library/Frameworks/Foundation.framework/Foundation, is there any dude come across the same issue, any direction or advise will be appriciated.

Create frameworks for iOS bundled with unity data and its library

This is regarding creating the framework in iOS, as I have a bundle of unity which I want to create a framework, with data with-holding and linking library from Unity as libiPhone-lib.a. So without adding any library in the bundle target, the compilation works fine, if I include libiPhone-lib.a file, it generates a warning as:
warning: implicit declaration of function 'UnitySendMessage'
The UnitySendMessage is a function which is being called from the dedicated libiPhone-lib.a framework.
Any suggestions regarding this concern will be really appreciated.
Thanks.
This error means that, in the file where it occurred, UnitySendMessage was called without the compiler having seen a declaration for the function. You need to edit the file and #import the header that contains UnitySendMessage (or #include if it is a .c file)
.
The Unity folks seem to have neglected to include a header declaring this function. You can either declare it yourself, or just ignore the warning.