Best way to define an immutable class in Objective C

Posted by Patrick Marty on Stack Overflow See other posts from Stack Overflow or by Patrick Marty
Published on 2010-04-05T01:15:41Z Indexed on 2010/04/05 1:23 UTC
Read the original article Hit count: 493

Hi,

I am a newbie in Objective C and I was wondering what is the best way to define an immutable class in Objective-C (like NSString for example).

I want to know what are the basic rules one has to follow to make a class immutable.

I think that :

  • setters shouldn't be provided
  • if properties are used, they should be readonly
  • accessInstanceVariablesDirectly must be override and return NO

Did I forget something ?

Thanks

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about best-practices