Design Element
Comment on "A Quick Objective-C 2.0 Tutorial"
by mmalc — Oct 28
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.

There really isn't any point in doing this, unless you're compiling for both GC and non-GC and that only makes sense if you're writing a framework. There are several design patterns and idioms that are different between the two environments (see the documentation). You should choose one and stick to it.

Re properties:

For differences between the 32- and 64-bit runtimes see Objective-C Language > The Objective-C 2.0 Programming Language > Properties > Runtime Differences.

By default, synthesized accessors are atomic in that the getter is guaranteed to return a valid value even with multiple active threads.

It is probably useful to add, per the documentation, that "atomic" does not mean "thread safe". Thread safety cannot be expressed at the individual accessor method level. The atomic attribute simply guarantees that the value returned from the getter or set via the setter is always fully retrieved or set.

For some additional examples of using Objective-C 2.0, see Cocoa Bindings Examples and Hints.

Back to "A Quick Objective-C 2.0 Tutorial"
Design Element

Copyright © Scott Stevenson 2004-2015