If your project is based on Kobold2D Preview 5 or earlier, you will have to perform the following steps to enable ARC in your project.
Open your project's workspace in Xcode. Browse to the BuildSettings group in the Project Navigator and locate the files BuildSettings-iOS.xcconfig and BuildSettings-Mac.xcconfig. To both files (if existing) add the following line at the end of the file:
Browse to the group ProjectFiles/Supporting Files and locate the files Prefix-iOS.pch and Prefix-Mac.pch. To both files add the kkARCSupport.h header file below the kobold2d.h header file:
This ensures that libraries such as cocos2d compile error-free with ARC enabled.
The kkARCSupport.h header file also makes the KK_ARC_ENABLED macro available, with which you can conditionally compile code if ARC is either enabled or disabled/unavailable.
|You will probably not need to use this macro, but you'll find it used in many of the Kobold2D template projects. It is used to keep the Kobold2D template projects compatible with non-ARC compilers (Xcode 4.1 or earlier) respectively for users who want or need to disable ARC. For example:|
In Xcode you can convert any Objective-C project to ARC with the built-in ARC conversion tool. With your project open you should select Edit -> Refactor -> Convert to Objective-C ARC... from the menu to start the conversion process.
Most of the time the conversion tool gets things right, but not always. If it fails for some reason please leave a message in the Kobold2D forum and include the code sample where Xcode reports a compile error.
Usually the issues are simple to fix, here are some guidelines:
- remove all calls to: release, autorelease, retain
- remove [super dealloc] and any other calls to dealloc
- in C structs prefix all id variables with __unsafe_unretained
- when casting id or other Objective-C class instance pointers from or to void*, cast the pointer with the __bridge keyword like so: id object = (__bridge id)somePointer respectively void* pointer = (__bridge void*)someObject