title: Obj-c protocol properties are not implemented in conforming class
body: <h1>Problem</h1>
  <hr />
  <p>I've come across an interesting issue and wasn't able to find any documentation on it... <strong>Sometimes <code>properties</code> declared in a <code>protocol</code> are not implemented in a particular class conforming to that <code>protocol</code> and a runtime exception occurs.</strong> Are <code>dynamic property</code> definitions optimized away under some strange circumstance? Can <code>protocols</code> not be used with <code>properties</code> that were made to be declared <code>dynamic</code>? Any insight into this would be greatly appreciated.</p>
  <p>Below are some more details.</p>
  <p>Given a <code>protocol</code>:</p>
  <pre><code>@protocol MyProtocol &lt;NSObject&gt;
      @property (nonatomic, strong) id someProperty;
  @end
  </code></pre>
  <p>and a class implementing the <code>protocol</code> like so:</p>
  <pre><code>@interface MyClass &lt;MyProtocol&gt;
  @end
  
  @implementation MyClass
  @dynamic someProperty;
  @end
  </code></pre>
  <p>I've noticed that <em>sometimes</em> I am unable to get any information from calling</p>
  <pre><code>class_getProperty(myClass, propertyName);
  </code></pre>
  <p>for the <code>properties</code> in the <code>protocol</code>. This only happens to <em>some</em> classes and seems to be sporadic.</p>
  <p>I'm running the latest Xcode 4 and linking against the iOS 6 SDK. I do have the pre-release Xcode 5 installed on the same machine though it is not the default (via xcode-select).</p>
  <h1>Example</h1>
  <hr />
  <p>If you run this code:</p>
  <pre><code>@protocol MyProtocol &lt;NSObject&gt;
  
  @property (nonatomic, strong) id someData;
  
  @end
  
  @interface MyObject : NSObject &lt;MyProtocol&gt;
  
  @end
  
  @implementation MyObject
  
  @dynamic someData;
  
  @end
  </code></pre>
  <p>and then you run</p>
  <pre><code>const char *name = [@&quot;someData&quot; UTF8String];
  objc_property_t property = class_getProperty([MyObject class], name);
  const char *attributes = property_getAttributes(property);
  </code></pre>
  <p>You WILL get meta data on the <code>property</code> EVEN THOUGH the <code>property</code> doesn't exist. In other words <strong>you don't need to synthesize the property to get it's attributes</strong>. The runtime still knows about it. Try it for yourself. The problem is that <em>sometimes</em> this doesn't happen. I want to know the conditions that cause the runtime to be unaware of the <code>property</code> attributes.</p>
  <h1>Temporary Fix</h1>
  <hr />
  <p>My temporary fix is to just copy all the <code>property</code> definitions in the <code>protocol</code> and paste them into the .h file:</p>
  <pre><code>@interface MyClass &lt;MyProtocol&gt;
      @property (nonatomic, strong) id someProperty;
  @end
  
  @implementation MyClass
  @dynamic someProperty;
  @end
  </code></pre>
  <p>This runs fine, though it is far from ideal. However, it suggests that my code is working correctly and the issue lies elsewhere.</p>
  <p>I'd be happy to provide more details or background if needed.</p>