title: Objective-C readonly properties in a subclass
body: <p>I have a superclass called SuperClass a read-only property. That looks like this: </p>
  
  <pre><code>@property (nonatomic, strong, readonly) NSArray *arrayProperty;
  </code></pre>
  
  <p>In a subclass I need an initializer that takes a instance of SuperClass as a parameter:</p>
  
  <pre><code>- (instancetype)initWithSuperClass:(SuperClass *)superClass
  </code></pre>
  
  <p>I created a GitHub sample project that shows what the problem is: <a href="https://github.com/marosoaie/Objc-test-project" rel="nofollow">https://github.com/marosoaie/Objc-test-project</a></p>
  
  <p>I cannot do <code>_arrayProperty = superClass.arrayProperty</code> in the initializer.
  I want to keep the property read-only in SubClass as well.</p>
  
  <p>Any ideas on how this could be solved?</p>
  
  <p>I know I could declare the property as readwrite in a class extension inside the SubClass implementation file, but I'm hoping that there's a better solutions than this.</p>
  
  <p>Edit:
  SuperClass.h</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface SuperClass : NSObject
  - (instancetype)initWithDictionary:(NSDictionary *)dictionary;
  
  @property (nonatomic, strong, readonly) NSString *stringProperty;
  @property (nonatomic, strong, readonly) NSArray *arrayProperty;
  
  @end
  </code></pre>
  
  <p>SuperClass.m</p>
  
  <pre><code>#import "SuperClass.h"
  
  @implementation SuperClass
  
  - (instancetype)initWithDictionary:(NSDictionary *)dictionary
  {
      self = [super init];
      if (self) {
          _arrayProperty = dictionary[@"array"];
          _stringProperty = dictionary[@"string"];
      }
      return self;
  }
  
  @end
  </code></pre>
  
  <p>SubClass.h:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import "SuperClass.h"
  
  @interface SubClass : SuperClass
  
  @property (nonatomic, strong, readonly) NSString *additionalStringProperty;
  - (instancetype)initWithSuperClass:(SuperClass *)superClass;
  
  @end
  </code></pre>
  
  <p>SubClass.m:</p>
  
  <pre><code>#import "SubClass.h"
  
  @implementation SubClass
  @synthesize additionalStringProperty = _additionalStringProperty;
  
  - (NSString *)additionalStringProperty
  {
      if (!_additionalStringProperty) {
          NSMutableString *mutableString = [[NSMutableString alloc] init];
  
          for (NSString *string in self.arrayProperty) {
              [mutableString appendString:string];
          }
  
          _additionalStringProperty = [mutableString copy];
      }
      return _additionalStringProperty;
  }
  
  - (instancetype)initWithSuperClass:(SuperClass *)superClass
  {
      self = [super init];
      if (self) {
  //        Doesn't work
  //        _stringProperty = superClass.stringProperty;
  //        _arrayProperty = superClass.arrayProperty;
  
      }
      return self;
  }
  
  
  
  @end
  </code></pre>