@property(readonly) 's initialization(initialize)

Benedict's Soapbox » Defining an Objective-C @property as Publicly readonly and Privately readwrite

  • readonly in outside interface
  • readwrite in inside interface and implementation (and synthesize)

XYZViewController.h

#import <UIKit/UIKit.h>

@interface XYZViewController : UIViewController
@property(readonly, atomic, retain) NSString *read_str;
@end

XYZViewController.m

#import "XYZViewController.h"

@interface XYZViewController ()
@property (readwrite, atomic, retain) NSString *read_str;
@end

@implementation XYZViewController
@synthesize read_str;

- (void)viewDidLoad {
  [super viewDidLoad];
  [self init];
}

- (id) init {
  self = [super init];
  if(self) {
    self.read_str = @"read str";
  }
  return self;
}