Disabling ARC... (AdMob SDK) - iphone

I've added all of the files and the frameworks needed to run the Admob SDK, but the problem is ARC...
My project uses ARC, but the AdMob files don't use ARC. I know you can disable ARC on specific files via the "Compile Sources" section which is under your project menu -> Targets (App Name) -> Build Phases
The problem is that the AdMob files don't show up in the Compile Sources section or any other section. You can see my AdMob folder in the Project Navigator...
Why won't these files show up so I can disable ARC on them?

Looks like you're not compiling Admob .m files, but rather it's a library you've included in your project and you're just using the .h files for the interfaces. So you might not need to worry about ARC v non-ARC issue at all. You can frequently use non-ARC libraries in ARC projects. The main issue is whether the library conforms to the rules outlined in Transitioning to ARC, such as the standard naming conventions, where the only methods that return an object with a +1 retainCount begin with alloc, new, copy, and mutableCopy.
You only need the -fno-objc-arc option if you're compiling the library's source in your project.

Related

GenericKeyChain KeychainItemWrapper.m does not compile when copied to another project

I compile and run Apple's GenericKeyChain sample code. No problems there. Now I want to use both files KeychainItemWrapper.m and KeychainItemWrapper.h in my new project and I get lots of compilation errors. I see that Apple's sample code is using ARC. Other posting here direct people to disable ARC for this file. That did not work. I have link the Security Framework on my new project.
My question is what should I do to get these two files compiled successfully on my new project. Why Apple sample code compiles with no problems.
The compilation errors are mostly ARC Casting Rules and ARC restrictions as well as Semantic Issue of using "release".
try the following 2 methods:
Go to Build Setting -> Swift Compiler -> Objective-C Bridging Header and set the path to /"Your project name"-Bridging-Header.h
ex path: myProject/myProject-Bridging-Header.h
Go to Build Phase -> Compile Source and pick the objective-c file (.m file) and set compiler flag to be "-fno-objc-arc"

Using Non-ARC Code in an ARC-Enabled Project - Adding Facebook

When i created my project, i made it to support ARC, so my project will support iOS 4.3 and above.
Now i need to integrate Twitter and Facebook to it. Both Facebook and Twitter frameworks given by the companies does not support ARC.
Most of the files have dealloc, and released its variables. Some say to scrap the project and redo it disabling ARC. But, i can't afford to do this, since i have done most of the stuff.
I added the FBConnect files (there were 4 of them) and added -fno-objc-arc as described in this tutorial. Still i get
file://localhost/Users/illepmorgan/Documents/Projects/illep/untitled%20folder/alphaproject/alphaproject/FBRequest.m: error: Automatic Reference Counting Issue: Existing ivar '_delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained
I need help, i can't redo this again.
Make sure that you added the -fno-objc-arc flag to each implementation file (.m file).
And then clean the project (Project menu -> clean) and build again. I have sometimes had to clean and build twice when doing this in class. Seems like a little bug.
there is actually a much easy way working in mixed ARC and Facebook none ARC .
see my post on how to use it
http://nabtech.wordpress.com/2012/02/02/facebook-ios-sdk-and-arc/

why do I get this error building a static library for my iPhone project using XCode 4?

I have an existing iPhone application, and I just wanted to make a static library out of the code, so that I can use it by a separate test application (within the workspace). The application compiles fine, but when I try to compile the library version (which has the same code files) I get the following error:
Lexical or Preprocessor Issue - "MyClass.h" file not found
However, the application still runs, even through there is this error. In fact when I compile the application (which uses the static library) it initially says no errors, and then after a second or two the above mention error then appears.
I'm basically doing:
Create a new target in the project using the Coco Touch Static Library
Add the .m files in the targets "Compile Sources"
Adding the .h files in the targets "Copy Headers"
Adding the same set of libraries in the "Link binaries with libraries"
Go into the Profile and modified the Target to be RELEASE
Any suggestions? Am I missing a step here?
I'll have a stab at this :-) I think it might be that MyClass.h has been set to private. Thus it is not added to header directory when you create the static library. You should check to see if this is so by checking the output header directory. If the header file is missing, then it's pretty sure thats whats going on.
Secondly, why use a seperate app for testing and therefore require building a static library at all? I have several static libraries and apps which I unit test with GHUnit. I do it by simply adding a new app target and configuring it to run the GHUnit iOS app. I can then add the classes I want to test and any testing frameworks such as OCMock without having to create separate projects. Basically it sounds like your testing methodolody is perhaps more complex than necessary. :-)
So, the issue turned out to be I had "-ObjC" set in the "Other Link Flags" option, which I'd put there as at one stage trying to get things working I read this was required - Dereks advice to review the compilation log worked well here

Thrift framework for iPhone

I'm currently stuck trying to get my objective c generated files to compile in my iPhone project. Basically it keeps telling me there is no such directory for the following four imports:
Thrift/TProtocol.h
Thrift/TApplicationException.h
Thrift/TProtocolUtil.h
Thrift/TProcessor.h
I'm following all the instructions on the Thrift wiki and have downloaded and compiled the Thrift framework in XCode but there is no information specific to iPhone development. I'm almost certain it's a problem specific to an iPhone project because if I create a new command line project in XCode, I can import those files just fine.
After retaining the services of some kind of sorcerer I have figured out how to get Thrift to work with the iPhone/iPad (or at least get it to compile okay).
First, you want to grab the objective-c files with this command instead of from the wiki:
svn co http://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cocoa/src/ thrift-cocoa
Then, make a new Xcode project by going to New Project, selecting Framework & Library and Cocoa Framework. Click create and save it somewhere nice. Right click on Targets and select Add -> New Target. Choose Cocoa Touch and then Static Library. Give it a nice name. Go to the target's Build tab in info and change the Base SDK to iPhone Device (I'm using 3.2 but you can use whatever) and change Architectures to either Standard (armv6 armv7) or Optimized (armv7). Under the General tab add the Foundation and Cocoa frameworks.
Drag all of the files and folders you got from the svn repository into the Classes folder in the project. Check the copy items box and check the boxes next to both targets. Remove TSocketServer.h and .m from the Static Library's Copy Headers and Compile Sources folders respectively. You can now build the Static Library (and Framework optionally).
Open the project you want to use Thrift in and go to your target's General tab in info. Add the Static Library you just created to the Linked Libraries list. It should be named libYOUR_TARGET_NAME.a. Under the build tab go to Header Search Paths and add the path to the Thrift project you just created and check the recursive box.
Finally you just need to change the import statements in the Thrift generated code by simply removing the brackets and replacing them with quotes. You can now build you iPhone project again.
Try adding those .h files to your Xcode project.

Can you reference Xib files from static libraries on the iPhone?

In my app, i currently have all my code separated into a static library, to make it easier to set up the xcode project targets for the actual app and for unit tests for my code. The problem with this is that i want to put most of my xib files in the static library as well, but it seems that when i run my app and try to reference the xib it can't find it unless it is included in the actual app's target instead of the static library target. Is it possible to have xib files and other resources included in static libraries that can be referenced by code in that same library, and if so, how?
No it isn't possible, because a static library is not the same as a "bundle".
A bundle is a directory that may contain all manner of files including resource files (xib), executable files and static libraries. It exists on the filesystem as a group of individual files.
A static library is a single file that contains classes, code and variables that were linked together by the library creator. It does not "contain" other files, it is essentially a database of compiled code.
Although it would be possible to put the data for the xibs in there, Xcode would have no way of knowing that it was in there, as it looks for them as individual files on the filesystem.
In Mac OS, you may create a "Framework" which is essentially a bundle of code, resources, settings etc which may be reused by multiple projects. However, Apple does not seem to support custom framework creation for iPhone OS.
Bundles
https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1
Static Libraries
http://en.wikipedia.org/wiki/Static_library
Reply to comment (won't fit in comment box)
No worries, I've been trying to do pretty much the same thing as you for the last week - I'd like to ship a "framework" of xibs, include files and .a libs to a client without giving them all the source code. I couldn't find a good way to do this with bundles either.
For whatever reason, Apple are being particularly obtuse about this - I can't see a reason for them to be so in the case of static libraries (dynamic libraries fair enough).
My solution for now is to manually create a package folder "Foo" that contains the following subfolders:
"include" -> put .h files here
"res" -> put .xib files here
"lib" -> contains "iphoneos" & "iphonesimulator" subfolders each with libFoo.a
Then zip this up and send to the client. The client then:
Unzips the package where ever they like.
Adds the "res" folder under the resources group.
Changes the following target settings:
Other Linker Flags = -Objc -lfoo
Header Search Paths = /include
Library Search Paths = /lib/$(PLATFORM_NAME)
I can probably automate the package creation with some build steps at my end, but the client is stuck with four slightly fiddly steps to get set up.
I found a perfect solution for this that does all the above automatically and more
https://github.com/kstenerud/iOS-Universal-Framework
Its an xCode plugin
It worked for me like a charm,
It works only for XCode 4 and above
Yes You can. add a xib file in your library as you would do for any normal project. Then in library project target add the xib file in copy Files section along with .a file.
In your main project where you are using the library, drag and drop the xib file where .a file for library is located.
Answer in including Xib files to your static library.
This time we have Xcode 11, you just create a bundle target in addition to your library target. The bundle template is available on macOS. Then from the library code, reference the bundle to be able to reference the nib. You distribute the library with the bundle.
A detailed video about using Xibs with static libraries below:
https://www.youtube.com/watch?v=WQI02KR9kQw
When distributing you could also create an SDK. JSON.framework did this in their SVN, and I successfully replicated this. You can see how this was done in http://hltypes.svn.sf.net/ in the hltypes-ios.xcodeproj and the iOS folder in the project.
Primarily you need to "install" into your build folder, and then you need to copy the specially formatted SDKSettings.plist. Then add the path to the SDK into "Additional SDKs" list in application project. Downside of composite SDKs are the need to restart Xcode 3.x whenever this mini-SDK is updated, and Xcode's insistence on constructing a composite SDK created from Apple's base SDK and your mini-SDK (which means you need to wait quite a bit).
Application project still needs to have .xib and other resources manually added.