This way if "get" performance is important:- (NSString*) title { return (title); } // title - (void) setTitle: (NSString *) newTitle { [title autorelease]; title = [newTitle copy]; } // setTitleFor maximum safety in the face of threads, use this:- (NSString *) title { return [[title retain] autorelease]; } // titleThis putstitle
into the current thread's autorelease pool, sotitle
is protected from being destroyed by someone else in another thread.- (void) setTitle: (NSString *) newTitle { // use a mutex or NSLock to protect this if (title != newtitle) { [title release]; title = [newTitle copy]; } } // setTitleBy making a copy of the object, you're protected from another thread changing the value underneath you.