Design Element
Comment on "A Quick Objective-C 2.0 Tutorial"
by Scott Stevenson — Oct 28
@Joachim Bengtsson: However, I worry that if one writes code like that before the GC is very mature and common (say, three years from now?), one might get problems later on

The collector is not experimental at this point. Xcode, for example, uses it. I've personally used it quite a bit.

Say you have to disable GC in your app because of some GC bug, or maybe you reuse the code in another project that doesn't have GC.

If you want to be absolutely sure, you can add all your retains and releases everywhere. But keep in mind this is only useful if you're constantly testing that code. That said, if you have a framework or library, I think it's better to not use GC so you don't limit your audience just to folks who have it enabled.

@Johan Kool: If a property is created for a NSMutableArray will the correct KVO notifications be sent when objects are inserted in, removed from or replaced into the array?

I forgot to mention this, but mutable foundation objects are not supported by the synthesized accessors. So you can declare the properly as NSMutableArray, but you have to implement the setter yourself so you can do -mutableCopy. The point is moot in this case, however, because NSMutableArrays do not normally publish changes when you alter them directly.

@Jonas Witt: stringWithFormat: supports more than just %@ placeholders, so you could save three lines of code and write the summary method as

True, but I was just demonstrating how to use NSNumber with the new methods. However, keep in mind that not all NSIntegers are 32-bit, so %d won't necessarily do what you expect.

@Henrik N: I'm afraid Jesper missed a couple of typos

I apologize for the typos. It was very late. :) They'll be fixed. (Fair warning, I'm may to edit your comment after I fix them since it will just be eating up space. In the future, it's probably better to just email me.)

@britt: in this declaration, assign is redundant; as it's the default

True, but I left it in intentionally for the purposes of this tutorial.
Back to "A Quick Objective-C 2.0 Tutorial"
Design Element

Copyright © Scott Stevenson 2004-2015