xcode 4 garbage collection removed? - objective-c

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?

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.

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.

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.

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.

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.

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"

Related

How do you get the 'use automatic reference counting' checkbox to show when starting a new mac application in xcode?

I just started learning about mac application development by doing this tutorial https://developer.apple.com/librarY/mac/referencelibrary/GettingStarted/RoadMapOSX/books/RM_YourFirstApp_Mac/Articles/GettingStarted.html
I feel dumb because I am stuck on the very first step. It says to make sure that the "use automatic reference counting" checkbox is checked, but I don't even have that checkbox.
This is a screenshot from the tutorial:
and this is a screenshot from my laptop while following along with the tutorial:
Since I am not even yet sure what automatic reference counting is I feel stuck because I don't know if it is important or not. Does anyone know why this option is not shown in my xcode?
The quick version: automatic reference counting is now the default, so just go to the next step.
The longer version: That tutorial appears to be written using Xcode 4.4 in the examples. The current version of Xcode is 5.1, and Apple has made a bunch of changes between then and now, some cosmetic and some more substantial.
One of those changes is that automatic reference counting (ARC) is now the default choice for new projects. ARC is a method of memory management where the compiler and runtime work together to keep track of which objects are still in use, and release the ones which aren't. When this technology was first introduced, it had some rough spots, and so it made sense to make it optional.
Apple is really pushing everyone to use ARC for all projects, so they removed the checkbox in the create project dialog. I'm not sure when this happened; may have been Xcode 5.0 or 5.1.
All that said: the tutorial you're using was written for an earlier version of Xcode than you're using. The big concepts are all going to still apply, but you'll run into issues from time to time where the screenshots don't look the same or the options are slightly different. So take a deep breath and just go for it. :)

Using Cocoa instead of the being deprecated Carbon framework

The Carbon framework will soon be deprecated in the near future.
My first question is whether the deprecation is targeted towards a particular release i.e. whether it's incompatible with 64-bit machines?
Also, since it is known to be deprecated, we are working towards removing the Carbon dependencies and using Cocoa framework instead. While removing some, I came across the use of EventRecord struct defined in the Events.h file. What should be the Cocoa equivalent of the above struct i.e. I should be able to loop through the Event records while using cocoa too.
Carbon does work with 64-bit machines, but it doesn’t work in a 64-bit mode, it works in 32-bit mode. You definitely want off it.
Cocoa has NSEvents (NSEvent.h), but a lot of what EventRecord appears to cover just isn’t relevant in Cocoa. Like, you don’t have to worry about “this portion of the window was uncovered” events—the system just calls “-drawRect:” on your NSView subclass.

Discover calls to methods not available in earlier iOS versions

I am building my app using iOS 5.0 as base SDK and iOS 3.0 as deployment target.
I know I need to check for existence of methods and classes when I work with features that are not available in the earlier iOS versions, but lately I've lost a few hours on a problem just to discover I was calling a method not available in some iOS versions. I simply did not notice it was a new method and did no check before to call it. The app of course compiled with 0 errors and 0 warnings.
This is a big problem because if I forgot some other check somewhere in the app, I will not know it until I or, worst, some user will activate that specific part of code.
Maybe I am missing something, is there some compiler option I can set to detect the calls I make to methods not available in the iOS deployment target? How do you deal with such a problem?
This link might point you in the right direction. Supporting mutiple ios Versions in your apps. It explains how to deal with taking advantage of the newer ios features while maintaining backwards compatibility. Hope that helps.
The only way to check for compatibility with a prior version of iOS, currently, it to test the app on an old non-updated device running that version of the OS.
If you can't find a device that old, even just to borrow for short time, then there may not be a good buiness reason to set the Deployment target that low.

Is it too early to use ARC for new projects?

I'm about to start a new project and I'm wondering whether I should use ARC or not.
I don't know if it's recommended to use ARC when I know that the new project will have quite a lot of dependencies on older code and external libraries which have not been converted to ARC yet (three20, shareKit, ASIHTTPRequest,..) ?
Some of the libs are quite big so I think it'll be tedious to add the -fno-objc-arc flag for each separate file.
It seems that Apple has went the ARC way definitely for IOS and every IOS developer will have to convert sooner or later.
But is it maybe just too early to jump on the ARC bandwagon yet ?
Compiled libraries will work with ARC out of the box. All ARC does is add the memory management automatically. It'll add the retains, releases etc. If the code is already compiled, it'll contain the necessary memory management, regardless of whether it was compiled with ARC or not.
If you're adding 3rd party code directly to your application, then you'll need to make sure that code works with ARC, but you don't need to change anything for compiled libraries and frameworks.
Apple are pushing ARC as the way forward, so for a new project, I don't think there should be any problems with using it.

How check the availably of all objective-c function in source code for Cocoa

When you read the Class Reference of every object of iOS, you will find:
Available in iOS 2.0 and later.
There are a program or a way to list all function and the minimum iOS system?
How can I know if the iPhone with iOS 3.0 will run all iOS function? I can check it in runtime with respondToSelector, but can be more easy with source code?
Set your project's base SDK to iOS 3, and see if it builds.
AFAIK there is no way to list all the APIs you use in your app into one list and check that you are building past the minimum for all those APIs. You will just have to check each one, one by one. Highlight the API in Xcode, and then click escape and it will tell you very easily.
But also I have to mention that this won't be extremely necessary since you should test on the minimum OS you are building for and if it crashes at any point then you have your issue for that certain API.