How to use a non-arc open source framework in the ARC Project

Source: Internet
Author: User

Address: http://maniacdev.com/2012/01/easily-get-non-arc-enabled-open-source-libraries-working-in-arc-enabled-projects/

Http://twitter.com/share

Looking at the title of this article, I believe many developers know that it should be a supplement to the arctutorial and guide page of another tutorial on this site.

Many people once asked questions about some open-source frameworks (introduced on this site). Surprisingly, they did not know how to use them in the ARC project-Fno-Objc-ArcFlag to disable arc.

If you use the open-source framework on this website and encounter the same problem, this article will introduce how to make non-arc libraries work in the ARC project.

There are usually two types"CodeAnd non-arc Code, we will introduce how to solve them in xcode4.

Scenario 1You have a non-arc project. You want to refactor it into an arc project (using xcode's refactoring function), but you do not want to refactor some of the Code.

To solve this problem, xcode automatically adds-Fno-objc-ArcFlag.

1.Select edit-> refactor-> convert to objective-C arc menu.
2.On the select targets to convert page, select target and click the arrow next to the target name to expand the file list.

3.Select all files that do not want to be restructured, right click (CTRL + Left click), select "uncheck-all", and then refactor.

As I did in cocos2d, cocos2d can easily work in the ARC project in this way. As shown in:

Scenario 2-You already have an arc project. You want to run some non-arc Code in the project, or you want to refactor the project yourself, but with some non-arc Code.

The answer is everywhere on the network. You will ask where to add"-Fno-objc-ArcMark? Let me tell you.

1.Open the "build phases" Window of target.
2.Change the compilerflags flag of a. m file (which you don't want arc to) to-fno-obj-arc (click the compilerflags column next to the file, and enter-Fno-objc-Arc). This flag is displayed on the right of the file, as shown in:

In this way, the interpreter will know that arc is not required for any file with this sign.

Conclusion

I cannot guarantee that this method is foolproof. For example, some libraries (such as libraries with nested projects) may be abnormal, but I think this is a very easy way to practice-all the newer open-source libraries mentioned on the website over the last few months can work in this way.

If you are using-Fno-objc-ArcWhen the flag links these libraries as a framework, see templatethat allows you to create universal frameworks easily.

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.