title: How to properly use a protocol-defined property in Realm predicates?
body: <p>I am trying to implement a cache system using Realm.</p>
  
  <p>Depending on classes, the cache should have different lengths. I've therefore defined a <code>StalenessChecking</code> protocol:</p>
  
  <pre><code>@protocol StalenessChecking &lt;NSObject&gt;
  
  @required
  //  nonatomic needed when using a getter
  @property (readonly, nonatomic, getter=isStale) bool stale;
  
  @optional
  - (void) setStaleness: (NSTimeInterval) duration;
  
  @end
  </code></pre>
  
  <p>and an object:</p>
  
  <ul>
  <li><p>Interface file (DziObject.h)</p>
  
  <pre><code>#import "Realm.h"
  #import "StalenessChecking.h"
  
  @interface DziObject : RLMObject &lt;StalenessChecking&gt;
  @property (readonly) NSDate* refresh;
  
  @end
  </code></pre></li>
  <li><p>Implementation file (DiObject.m)</p>
  
  <pre><code>#import 'DziObject.h'
  @implementation DziObject
  {
     NSTimeInterval stalenessInterval;
  }
  @synthesize stale = _stale;
  
  - (instancetype)init
  {
      self = [super init];
      if (self) {
      _refresh = [NSDate date];
      stalenessInterval = 120.0;
      }
  return self;
  }
  
  - (bool) isStale {
       return [[NSDate dateWithTimeInterval:stalenessInterval sinceDate:_refresh] timeIntervalSinceReferenceDate]&lt; [[NSDate date] timeIntervalSinceReferenceDate];
  }
  
  - (void)setStaleness:(NSTimeInterval) duration
  {
      stalenessInterval = duration;
  }
  @end
  </code></pre></li>
  </ul>
  
  <p>I then call them from a Facade:</p>
  
  <p>Interface:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface SDK_Facade : NSObject
  
  + (void) createDziO;
  @end
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>#import "SDK_Facade.h"
  #import "DziObject.h"
  
  @implementation SDK_Facade
  
  + (void) createDziO
  {
  
  DziObject *dziO = [[DziObject alloc] init];
  // both work fine
  if (dziO.isStale) {
      NSLog(@"Is stale");
  }
  if (dziO.stale) {
      NSLog(@"Is really stale");
  }
  
  // Query Realm for all results less than 2 minutes old
  // TODO: -- currently crashes
  RLMResults&lt; DziObject *&gt; * dzios = [DziObject objectsWhere:@"stale == %@", @YES];
  NSLog(@"DziOs: %lu", (unsigned long)dzios.count);
  
  // Persist your data easily
  RLMRealm *realm = [RLMRealm defaultRealm];
  [realm transactionWithBlock:^{
      [realm addObject:dziO];
  }];
  
  // Queries should update in realtime
      NSLog(@"DO: %lu", (unsigned long)dzios.count);
  
  }
  
  @end
  </code></pre>
  
  <p>I get an ugly crash:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'Invalid property name', reason: 'Property 'stale' not found in object of type 'DziObject'</p>
  </blockquote>