Ray's playground

 

Copying Objects(Chapter 17 of Programming in Objective-C 2.0)

The Foundation classes implement methods known as copy and mutableCopy that you can use to create a copy of an object.This is done by implementing a method in conformance with the <NSCopying> protocol for making copies.

Use of nonatomic here tells the system not to protect the property accessors with a mutex (mutually exclusive) lock People writing threadsafe code use mutex locks to prevent two threads from executing in the s me code at the same time, a situation that can often lead to dire problems. But these locks can slow programs down, and you can avoid

using them if you know this code will only ever be running in a single thread. If nonatomic is not specified or atomic is specified instead (which is the default), then your instance variable will be protected with a mutex lock. In addition, the synthesized getter method will retain and autorelease the instance variable before its value is returned. 

posted on 2010-10-25 17:06  Ray Z  阅读(259)  评论(0编辑  收藏  举报

导航