So many errors occurred when I using the ARC convertion tool - ios

I have a project previously built in iOS 4.3. When I tried to invoke the “ARC” conversion tool with
Edit > Refactor > Convert to Objective-C ARC
from XCode 4.5.2, the tool reports many errors. Some are supposed to be modified automatically by itself, for example the keywords autorelease/release/retain should not be used.
The errors seem too many (1,987 occurrences) to resolve by hand. Are there any configuration options that i am missing or should something else be done?

If you are using existing libraries you can simply not use ARC for those libraries and begin using it throughout your app by using a flag.
Add this to your library or files in question to ignore ARC
-fno-objc-arc

i think you have used any third party libraries, if you have used any third party libraries then it won't helps you.that means in this situation it wont automatically converts it to ARC.
Unfortunately ARC manages memory only for objective-c objects, if you have used any C or C++ files then in this case you have to handle memory management yourself

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.

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.

IOS arc disabling for part of code [duplicate]

This question already has answers here:
How can I disable ARC for a single file in a project?
(18 answers)
Closed 9 years ago.
I'm a newbie to IOS technology. I have been developing an app, in which I have to add around 10,000 mkannotations to my map. So I prefer to use clustering algorithm (probably using k_means). However, I found this beautiful external library at (https://www.cocoacontrols.com/controls/adclustermapview)
When I complied the example framework of this project and ran it on simulator everything works fine, however, when I add the required files to my project as they described, it raises a lots of errors regarding
retain
release etc.
So I understand there is some issue with the arc compatibility in the project
Here are my questions
These retain, release methods being used in some project, does
that mean that they are developed with old versions of IOS?
If so, how do I resolve these error, other than manually removing them?
Is there a method in IOS, which allows me to compile a code
partially using one compiler and the remaining using other?
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
In xcode Edit-Refactor-Convert to Objective-C ARC select your app then check button.Finally click save button.
These retain, release methods being used in some project, does that
mean that they are developed with old versions of IOS? NO
If so, how do I resolve these error, other than manually removing
them?
Is there a method in IOS, which allows me to compile a code
partially using one compiler and the remaining using other? You can disable ARC for some files.
This problem might be coming because you must be using ARC in your project while this framework is not. To remove ARC for particular classes go to Targets, then build phases tab, under the compile sources group add '-fno-objc-arc' as the compiler flag. This will make sure that ARC is skipped while compiling this class..

iOS SDKs: Renaming a lot of classes

I'm developing an iOS SDK that integrates other SDKs (Facebook SDK 3.5, for example).
To prevent collisions and allow my customers to import those SDKs as well, I want to rename all of the classes/enums in my code (for example, rename FBSession to RDFBSession, etc).
Is there an easy way to do this instead of going class-by-class and using Xcode's rename feature?
Apple provide a command-line tool called tops(1) that is designed for scripting large-scale code refactoring (renaming C functions, Objective-C methods, classes, and other tokens):
tops -verbose replace "FBSession" with "RDFBSession" Sources/*.[hm]
If you have a lot of replacements, you can put all of the replace... commands into a file that you pass with the -scriptfile option. The man page has more information on the more complex commands/options (and examples).
Xcode also offers textual Search and Replace. This will be faster than individual refactors, but it is ultimately less automated. You can make the step by step refactoring faster by first minimizing the project to the relevant dependencies/sources (if possible).
However, renaming the declarations in a library will not alter the symbol names of its associated binary. If it is distributed with a binary, then renaming will just result in linker errors or (in some cases) runtime errors.
The best idea if you need to use a 3rd party library which your clients might also use is to simply inform them they need to link the library with their app, then publish the version(s) the current release supports so they know they have some extra testing if they go too far ahead with some libraries.
I think that a better approach than simply renaming your classes would be to download Facebook's open source code, rename the classes there and compile a new static library with a set of renamed header files. Then you can be sure that no collisions occur and that you're using symbols that you named yourself.
I must warn you though - working like this may make updating the SDK a nightmare regardless of how you tackle this specific issue.

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/

Resources