zoukankan      html  css  js  c++  java
  • Easily Get NonARC Enabled Open Source Libraries Working In ARC Enabled Projects

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

    The topic of this post is one that I’m sure many developers will know about especially since it is a footnote in several of the tutorials on the ARC tutorial and guide page on this site.

    I’ve received so many inquiries about how to get open source libraries mentioned on this site and it’s surprising how many don’t know how to implement the -fno-objc-arc flag for using non-ARC enabled code within ARC enabled projects.

    If you don’t know how to do this working with many of the open source projects on this site can be a living hell – so here’s the easy way to get nearly all of those Non-ARC enabled libraries working within your ARC enabled projects.

    So here are two scenario’s you will likely run into when mixing ARC enabled and non ARC enabled code and how to solve them easily in Xcode 4.

    Scenario 1 – You have non-ARC project that you want to refactor to enable ARC (using XCode’s refactoring feature), but there is existing code that you do not want to convert.

    Here’s how to solve this, when you do the refactoring deselect the files that you don’t want to convert to arc, and Xcode will automatically add the -fno-objc-arc flag to those files.

    1. Choose Edit->Refactor->Convert to Objective-C ARC in the Xcode menu.
    2. On the Select Targets To Convert screen select your targets, then click the little arrow beside the target name to expand the list of files.
    3. Highlight the files that you do not want to convert then right click (or ctrl-click) and select uncheck-all to deselect all the files you want to convert to ARC.  Then proceed as usual with the refactoring.

    You can see this in the screenshot below where this has already been done with Cocos2D (btw, this is the easy way to get the Cocos2D template projects working with ARC):

    Scenario 2 – You already have a project using ARC and want to add in some non-ARC enabled code, or you want to refactor the project yourself and don’t want to use ARC with some of the code.

    I’ve seen this come up all over the internet in answers, and people asking where to add the -fno-objc-arc flag so here’s how it’s done.

    1. Bring up the build phases tab for the appropriate target.arc1
    2. Change the compiler flags for the specific code files that you do not want to enable ARC for to -fno-obj-arc (simply clicking on the compiler flags section beside the file, and enter -fno-objc-arc).

    The flag will show up beside the file like in this screenshot if done correctly:

    Continue as normal – the compiler now knows not to use ARC with the files that you flagged.

    Conclusion

    I can’t verify that it works in every case as there are some libraries with  things such as embedded projects that can mess things up, but in my opinion it’s good to try the easy way first – and I haven’t seen it not work with any of the newer open source libraries I’ve mentioned on this site in the last few months.

    You might want to look at this template that allows you to create universal frameworks easily if you run into issues with the -fno-objc-arc flag and link to those projects as frameworks.

  • 相关阅读:
    课后作业07--二分法查找算法代码
    检索03 -- 二分法查找
    课堂随笔05--冒泡排序
    课后作业 06 -- 小数后几位精确判断并输出
    课后作业 05 -- 输出一段带字母与数字的随机数
    课后作业 04 --DateTime应用,判断多久后生日之类
    检索02--随机数种子的一些概念和理解
    课堂随笔04--关于string类的一些基本操作
    P1174 互素
    P1001 第K极值
  • 原文地址:https://www.cnblogs.com/simonshi2012/p/2451598.html
Copyright © 2011-2022 走看看