Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 12. Properties > Hidden Setters for readonly Properties

Hidden Setters for readonly Properties

You can use a similar strategy to provide a hidden setter (for internal use) for properties that are publicly declared as readonly. You do this by redeclaring the readonly property in an extension in the class’s .m file (see Chapter 11, “Categories, Extensions, and Security”). To make employeeNumber in the Employee class from Listing 12.7 and 12.8 writable internally, you can modify Listing 12.8 to look like this:

#import "Employee.h"

@interface Employee ()
@property (nonatomic, readwrite) int employeeNumber;
@end

@implementation Employee

@synthesize employeeNumber;
@synthesize name;
@synthesize supervisor;
@synthesize salary;
...

@end


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial