xcode 4 garbage collection removed?

2020-08-26 10:51发布

I am learning Xcode and objective c, but the book I am reading is using the older version (3.2) of Xcode. One chapter, which is completely dedicated to memory and leaks, says I need to turn on garbage collection through Project Settings > Build. However, I can't find the garbage collection setting. Has it been removed or am I just missing it?

6条回答
Rolldiameter
2楼-- · 2020-08-26 11:20

Xcode 4 still has Garbage Collection, all you do is go into your project (the top option in the navigation bar with the big xcode project icon). Select your target which should just be the name of your app with the application icon next to it. When you select that, along the top there is a bar with different options, such as summary, info, build settings etc. Hit "Build Settings" and type "garbage" in the search field. Then set garbage collection to required.

One very important note about GC is that it is officially deprecated as of Mac OS 10.8, which means you should be transitioning your code to ARC if possible because GC might not be around for much longer.

Update: See other answers for enabling GC in current versions of Xcode. As I stated above, you should be transitioning to ARC if you haven't already.

查看更多
做个烂人
3楼-- · 2020-08-26 11:21

As of XCode 4.4 the garbage collection build flag is user defined (see the very end of the build settings list).

GCC_ENABLE_OBJC_GC supported

Valid build settings are:

  • unsupported: The application cannot load code that requires garbage collection. The loadable bundle cannot be loaded by an application that requires garbage collection.

  • supported: The application can load code that supports or requires garbage collection. The loadable bundle can be loaded by an application with any level of garbage-collection support.

  • required: The application can load only code that supports garbage collection. The loadable bundle can be loaded only by an application that supports garbage collection.

查看更多
虎瘦雄心在
4楼-- · 2020-08-26 11:25

Garbage collection is very much fully supported in Xcode 4. Xcode 4, itself, is a GC'd application.

GC is also very much not available in iOS. If you are writing an iPhone/iPad app, you can't use GC.

查看更多
再贱就再见
5楼-- · 2020-08-26 11:26

As of Xcode 4.3.3 the only setting available for parameter "Objective-C Garbage Collection" under section "Apple LLVM compiler 3.1 - language", Build Settings for your target app = "Unsupported"

查看更多
三岁会撩人
6楼-- · 2020-08-26 11:27

That's a challenge but you might be able to get it done - here's a starting point to think about in relation to PDF generation:

iOS SDK - Programmatically generate a PDF file

If you can generally follow what is going on there, you might be OK.

查看更多
戒情不戒烟
7楼-- · 2020-08-26 11:38

Xcode 3.2 is still available for download - in fact, 3.2.6 was released within the past week or two, so it's not exactly "old and busted." :-) Xcode 4's interface is very different, so given your tight schedule and your need to start from square one, you might be better off using 3.2 for now. That will certainly make it far easier to use the book you have.

查看更多
登录 后发表回答