RestKit in a Workspace - ios

I have a workspace set up in Xcode. It contains a number of static library projects that I link to in my main project.
The process of linking to these projects is much longer than it should be. But the key for me in getting this to work was removing the -ObjC linker flag from my build settings. This kept me from getting duplicate files when I used a library in more than one place.
But this gave me a problem when trying to include RestKit in my project, because the documentation says that the -ObjC linker flag is necessary, which I have found to be the case.
Is there a way of including RestKit in a workspace like this and linking to it like any other static library? Without having to use the -ObjC linker flag?

If you are planning to target your app for IOS 5 and above then you can try using the built-in NSURLConnection along with NSJSONSerialization class (If you return JSON response) for the purpose.

Related

Duplicate symbol(s) for architecture(s) [arm7, arm64]

I have imported a new version of a framework in my SDK. Anyway, I am not able to build on iPhone 6 running iOS 9.0.1 because of the following error that's driving me crazy:
duplicate symbol _IPDJobStatus in:
/Users/akiki/Desktop/iOS 9 Test/MPSDK/iPD.framework/iPD(IPDDevice.o)
/Users/akiki/Desktop/iOS 9 Test/MPSDK/iPD.framework/iPD(IPDAdministration.o)
ld: 5 duplicate symbols for architecture arm7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is happening for the same symbol _IPDJobStatus being found twice in 5 files. The same is happening on iPhone 4S running iOS 9.1 with arm64 architecture. To import the framework, I deleted the old one from the project, imported the new one and check into the Link Binary with Library section wether the framework reference links to the correct updated file. Before asking I have tried to perform the following actions:
I searched for the duplicate symbol inside the project scope with no result.
I'm not importing a .m file by accident.
The Compile Sources of the Build Phases project settings doesn't include any duplicate file.
The framework headers references in Headers of the Build Phases project settings link to the proper files.
I tried to clean the project, empty the Derived Data folder, quit and relaunch Xcode.
I added the -ObjC linker flag (in this case the duplicate symbols goes from five to only one).
I switched the No Common Blocks compiler setting to NO, though it has the same error with or without it.
I created a new empty project and imported the framework there. In this case I was able to build, so the problem must resides in my SDK.
Could someone please give me some help?
You can check your project directory may be there available framework. If available then delete it.
I was able to solve the same problem with the following code.
Add this to the Library Search Paths in Build Settings and make sure you select recursive, delete other library paths which might be absolute paths.
$(PROJECT_DIR)
May be it will help you.
You can not make constant type variables of same name & type in two or more classes.
_IPDJobStatus is this constant type variable?
change it to some other name for different classes.
Here you can see the same issue
It means in you project multiple copy of same View Controller instance (i,e means duplicate).
Possible observation:
This IPDJobStatus variable contains in the class IPDDevice or IPDAdministration of the framework is duplicate. Please check this.
Note: You should not have/create a class which already have in any other framework either Xcode's default or 3rd party framework.
For example: UIkit framework have class name "UIApplication" (i.e UIApplication.h, and UIApplication.m). So, if you create you class name "UIApplication". this error will occur. Same case for also 3rd party framework.

Can the -ObjC flag be applied selectively to static libraries?

TL;DR
How can I make the -ObjC linker flag target a specific static library and not all the static libraries I am linking against in order to avoid unused object files being linked in with my app?
Too Long; Did Read
So you are developing a new iOS app and you add in your homegrown "objcutil" static library which contains a variety of useful Objective-C classes (not implemented as categories) to do various things that have been useful in the past. So far, so good, and only those object files that are being referenced in the utility library are being linked with the app.
Then you decide to integrate the Google Maps SDK which wants you to use the -ObjC Other Linker Flags and all of a sudden dependencies in the utility library fail to be resolved, because you haven't configured Xcode to link to those libraries.
OK I can resolve the missing dependencies easily enough, however you now have unused object files and library dependencies that you don't need and you'd like to be a bit tidier than that.
So how do you avoid OCD overload?
Some reference from the ld manpage:
-ObjC Loads all members of static archive libraries that define an Objective C class or a category. This option does not apply to dynamic
shared libraries.
Xcode Version: 5.1.1
OSX Version: 10.9.4
OK so the answer is to use -force_load instead of -ObjC as -force_load is more focused.
So WRT to the Google Maps SDK, if you followed the instructions and copied the static framework into the app project directory, then the framework will be in the project root directory and you can remove -ObjC from the Other Linker Flags and replace it with
-force_load GoogleMaps.framework/Versions/Current/GoogleMaps:
Nothing else needs changing.
For other libraries you will need to use the full static library path as the argument to -force_load.

why CocoasPod increase IPA size? how to reduce the size?

CocoasPod is good, But sometimes it's not.
Why? Because there is a flag call "-ObjC" in your project.
It will pull ALL OBJECT FILES into your resulting binary.
For example, an empty project with "pod 'AFNetworking'" and the flag "-ObjC" is on, that will cause the binary will be 7MB. 7MB for an empty project, that's suck.
Some frameworks like Google Map SDK need the flag "-ObjC" is on.
So, if your project with "AFNetworking pod" and "Google Map SDK", it will cause the binary will be 17MB.
So my question is:
How can I turn off the "-ObjC" flag for special Library?
For example, just keep the "-ObjC" for Google Map SDK, but turn it off on AFNetworking.
You should try the answer to this question so as to reduce the .ipa size.
In general, adding a static library to your project in Objective-C
will pull ALL OBJECT FILES into your resulting binary because cocoa
pods installation adds -ObjC flag to your linker settings, and as
stated in linker manual:
-ObjC Loads all members of static archive libraries that implement
an Objective-C class or category.
This flag included to solve problem with linking categories, because
by default linker will not include object files containing only
categories into resulting binary.

Significance of -ObjC value in Other Linker Flags: GMaps SDK

I was trying out google maps sdk integration with iOS 6.1. I am successfully able to populate gmap on iOS simulator by using instructions given on
GMaps for iOS starting guide
Then what the issue with it:
It works great when I use it as a separate project. But when I club the above project code with my existing application, then it behaves weird, and all the errors generates due to inclusion of -ObjC value in Other Linker Flags in Build Settings.
Error
duplicate symbols for architecture i386
When I skip step 7 (GMaps iOS), it doesn't give errors. Due to exclusion of -ObjC value, it doesn't able to identify a specific GMaps library class and its method:
[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent
My iOS application background:
Using a third party library SUP (Sybase Unwired Platform). Connecting SAP to iOS application. I guess there is something ambiguous with SUP environment enablement (Build settings) when I am trying to add GMaps library.
Seeking for your advices.
Thanks!
There many posts on SO about the duplicate symbols for architecture i386 error. Usually it means that you defined the same symbol twice in the one namespace. The last time I got this error was because I accidentally included a .m file instead of .h header file.
Have you checked the Build Architecture?
Try setting Build Active Architecture Only to Yes.
I was facing the same issue Today! -ObjC linker flag - When trying to add it to "Other Linker Flags" I get an error
I solved my problem, Here is what I'd suggest. Take your original project (without Gmaps and with SUP) and add the -ObjC flag to it. Are you still getting an error? If so, take Gmaps out of the equation. If you are still getting an error check in the warnings about which files it is warning you about. My problem was that I had two files libGoogleAnalytics.a and libGoogleAnalytics_debug.a and for some reason they could not coexist with the -ObjC.
Long story short, you need to find what libraries Gmaps is using that you already have in your project and remove one of them.
Please try this…
step 1: Add '-ObjC' to other linker flags in 'Build Settings' of your 'target' only not to the 'project'

Ho can I use adMob library for iOS without using -all_load linker flag

I'm adding adMob provide by google to my iOS app and I'm stuck on this part of the installation:
Add -all_load under Other Linker Flags in the project build info
If I add that flag, then another third party library breaks giving me the error message:
ld: duplicate symbol _vw_chartype_table_p in /Users/josh/ Projects/app/libs/libvt_universal.a(vw_ctype-3279EF26D0C25F3A.o) and / Users/josh/Projects/app/libs/ libvt_universal.a(vw_ctype-34AB9EC0B46D954C.o) for architecture i386
Is there any way to use the adMob library without using -all_load? For example, I've tried -force_load $(SOURCE_ROOT)/adMob/libGoogleAdMobAds.a
but
ld: file not found: /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
The reason Google suggests using -all_load is that they are using categories in their code, and Objective-C libraries with categories are not properly loaded by the llvm linker (well that was the case in 4.3 xcode, not sure about 4.4 with the newer clang).
So, I guess if you are brave you can try to just remove the all_load flag. It should build fine. If the bug is NOT fixed, what will happen is when you run your code, it will crash, since none of the categories the library uses will have been loaded. This might be a good thing to do in any case, as your project should build, and if it does not you can fix those problems first.
What I do suggest you do is use -force_load, which has llvm load the categories in the adMob library (among other things). To use it you MUST have a fully qualified path (ie starts at '/') to the library. Obviously if you use Terminal and run:
ls -l /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
its going to fail. So enter the proper path - hard coded - for now to just see if you can get the project to first build, then run. If it does you can later figure out what is the appropriate $(VAR) to use to find it inside your project.

Resources