Problems With an old Project on Xcode 4 - ios

I'm trying to compile an old project that I changed the UI a bit, but I've updated to Phonegap 1.0 and Xcode 4, so I'm getting this errors:
What should I do?

It looks like you now have ARC (Automatic Reference Counting) set on in the project. To use ARC your code will have to change, one of the changes is the way the autoreleasepool is created/drained.
Other things that are not available are retain. release and autorelease, the compiler generates all of these behind the scenes as necessary. This all works iff all of the Obj-C naming conventions have been followed.
Xcode has refactoring help to convert a project. However this many not be appropriate in your case, if that is true turn it off in the project/target build settings:
ARC can be disabled on a file-by-file basis:
There is no problem mixing ARC compatible files with non-ARC files. This can help bring legacy projects to ARC. ARC is the future.

Related

Force ARC in static iOS library

I am maintaining a static iOS library i inherited from a former coworker using Xcode and Objective-C. The code contains a lot of
#if __has_feature(objc_arc)
and i was wondering if i can just assume that arc is always available? The library gets distributed to customers so another question would be: Do they maybe have to change something to use my library after i "forced" it to use arc? I already tried to find something about it and so far it seems to me that you can use arc frameworks in non-arc projects. But i'm not completely sure if i got that right and also i don't want any customer to do extra work because of that.
If you're distributing it in compiled form, then yes, it either has ARC on or it doesn't, and that's completely under your control. The user of the binary can't change it afterwards; ARC "happens" at compile-time.
If you're distributing it as source, you could document the requirement for ARC, and issue a compilation error if it's lacking by putting a similar guard in just one place:
#if !__has_feature(objc_arc)
#error "MyLibrary requires compilation with ARC"
#endif
and remove all the others scattered around.
Finally, code that's compiled with ARC can be freely linked with non-ARC code. The only problem arises if the MRR code does not do proper memory management, but I would classify that as an exposition of an existing bug in that code rather than a problem caused by using ARC.

use ARC library in non arc project

I am developing an IOS application. I don't use ARC, my project is non ARC project. Bu I'm using a library developed for the ARC. This librar is AFImagePager. This librar is image gallery. So I added a flag What is -fobjc-arc at required file. But when running the application gives memory error. Memory usage is constantly increasing, not decreasing at all. Is this normal
You don't have to enable ARC for your project, using ARC isn't just a matter of adding -fobjc-arc, it's more involved than that.
The only thing that you can't do if you use a library that is ARC, is use GC, because that's not compatible.
If your project was MRR and working fine, continue to do so.
For your application, make sure you are doing proper memory management. That is the only thing that I can think of that might be causing those errors. Tip: go to Product -> Analyze… and check on all the memory issues it reports.

Link two seperate cocoa touch projects

i have this problem for a while now. I have iPhone project which was built with non ARC. And now somehow i need to add another smaller project to it, but that project was built with ARC. I have tried to copy files one by one, but ass soon as i was done, i got lots of ARC errors and some with Security.framework... Can someone help me? Or give me some ideas how should i proceed?
I have tried this but it didnt solvet issius with ARC...
ARC is done at compile time. ARC-enabled source code files need to be compiled with ARC, non-ARC source files need to be compiled without. It is a s simple as that. ARC is nothing but syntactic sugar injected by the compiler.
I have had this problem with some third parties not entirely migrated to ARC. Just create a static library around these files.
You could also try to change the per-file compiler options (see this question: How to disable ARC for a single file in Xcode 5?), but I would recommend against it since it will just become a maintenance burden in the end.
And of course, if it is your source code and not some third party: Migrate it to ARC. It is worth it.

Transitioning one separate file to arc

I have a project that is already transitioned to ARC. Now I'm trying to include an existing file from the other project, which is not using ARC and I want it to be ARC-compliant too: release-retains, [super dealloc]s gone from this file, quick fixes, other stuff "Convert to Objective-C ARC..." does.
The problem is I can't use the Edit->Refactor->"Convert to Objective-C ARC..." tool for this. If I select only this file in "Select Targets to Convert" screen I'm getting "Cannot Convert to Objective-C ARC" message because of errors like: "#synthesize of 'weak' property is only allowed in ARC or GC mode". But they are already in ARC mode indeed! Also numerous warnings: "Method possibly missing a [super dealloc] call"
If I select all files except marked with -fno-objc-arc while converting, I get only errors about weak properties.
Of course I can build and delete the release-retains manually but why to walk if there is a bus (Conversion tool)... So can I auto-transition a separate file to ARC?
Update: I do not want ARC to be turned off for this file with -fno-objc-arc flag, I want ARC used in this file.
If you insist on making Xcode do the work, create a new Xcode project and deselect "Use ARC" when creating it. Add the files to convert, and convert the project to ARC. Take the modified files and import them into your other project.
It's probably simpler, however, to convert the file manually. This is not difficult, even for a large file or an entire project. Just lean on the compiler: build your app, walk through the errors and simply delete all retain/release calls and convert any NSAutoreleasePools to #autoreleasepool {}. You may also need to add __bridge casts if interacting with core foundation types.
It sounds like you'll have to convert this file to ARC manually, instead of relying on the automatic conversion tool. You'll need to go through the file and remove all of the release, retain etc. I've done this before, and while it takes a while, it's not too painful. Rely on the error messages from Xcode to guide you what needs to be fixed/removed in the code.
Here's a couple of links I found that may help. Also look at Apple's ARC docs and WWDC 2011 talks (referenced at the bottom of the second link).
Xcode ARC conversion tool issue
http://blog.mugunthkumar.com/articles/migrating-your-code-to-objective-c-arc/

Framework iOS ARC

I am creating a static framework and will be using it across multiple applications. In the framework code I have disable ARC flag and is set to NO.
Other projects where I will use the framework may have ARC set to YES or NO. So if there is mismatch in ARC flags in Framework and the project where the framework is used, the application crashes since it tries to deallocate something which is already de-allocated.
Is there a solution to the above issue?
Regards,
Nirav
ARC is a compile time setting, so it is per-file not per-application. All you have to do is make sure your code in each file agrees with the compiler about if it's using ARC. If you want to throw an error if a file isn't using ARC when it should be, use something like:
#if !__has_feature(objc_arc)
#error This file should be compiled with ARC enabled
#endif
and similarly for detecting the opposite.

Resources