How to enable ARC in the cocos2d Project

Source: Internet
Author: User

How to enable ARC in the cocos2d Project
The basic idea is not to support the separation of the ARC Code and the support of the ARC. You can set the compilation options in xcode to make the code that supports and does not support the ARC coexist.

Cocos2d is the most popular 2d game engine in ios app development. However, during cocos2d development, Apple has not launched the automatic reference counting (ARC), a mechanism to assist in memory management, the compiler automatically adds memory management statements to the code to prevent memory leaks and crashes caused by developers' negligence ). so if you use the cocos2d template to generate a project, ARC is disabled. if you enable ARC directly, many compilation errors will occur.

If you want to enjoy the benefits of ARC, you have to find a solution on your own.

The basic idea is to use ARC instead of cocos2d files. In xcode, some source files can be specified using arc.

 

The method described in this article is to compile cocos2d as a separate project (without arc), reference the library file to the enable ARC Project, and modify it a little.

However, there is a simpler method in the response (This reply is also really rude, and you are interested in looking at the response from horseshoe7). The actual steps are as follows:

Note:

-If you use a version later than cocos2d v2.0, you are lucky. Errors will not occur in versions, or. You can skip this step.

-If you use cocos2d v1.1, you will only encounter problems 4, 5, 6, and 7, which can be skipped.

-If you use 1.0.1 like me, you must modify all of the following.

1. Use LLVM: Set the default compiler in build setting, search for "LLVM", and select Apple LLVM compiler 3.1

2. enable ARC: Search for auto and set Object C Automatic Reference Counting to Yes.

3. complie source build phase lists all. m file, check the files in cocos2d, press enter, enter "-fno-objc-arc", and press Enter. in this way, these files will not be checked by ARC. we recommend that you use the AppDelegate generated by cocos2d. m and RootViewController. m is off ARC. only use ARC in your own code.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.