title: Objective-C: Custom BOOL accessor (getter & setter) methods
body: <p>I know someone already asked about <a href="https://stackoverflow.com/questions/4099062/writing-getter-and-setter-for-bool-variable">Writing getter and setter for BOOL variable</a>. But, if I'm defining a custom getter &amp; setter methods <code>setImmediate</code> &amp; <code>isImmediate</code>, respectively, I'd like <code>passcode.immediate = NO</code> to work too.</p>
  
  <p>I do not have any instance variables, but maybe I should? I could add one for <code>NSDate *lastUnlocked</code>.</p>
  
  <p>Here's the relevant code so far:</p>
  
  <pre><code>// PasscodeLock.h
  
  extern NSString *const kPasscodeLastUnlocked;
  
  @interface PasscodeLock : NSObject {
  
  }
  
  - (BOOL)isImmediate;
  - (void)setImmediate:(BOOL)on;
  
  - (NSDate *)lastUnlocked;
  - (void)resetLastUnlocked;
  - (void)setLastUnlocked:(NSDate *)lastUnlocked;
  
  @end
  
  
  // PasscodeLock.m
  
  #import "PasscodeLock.h"
  
  NSString *const kPasscodeLastUnlocked    = @"kPasscodeLastUnlocked";
  
  @implementation PasscodeLock
  
  #pragma mark PasscodeLock
  
  - (BOOL)isImmediate {
      return self.lastUnlocked == nil;
  }
  
  - (void)setImmediate:(BOOL)on {
      if (on) {
          [self resetLastUnlocked];
      } else {
          self.lastUnlocked = nil;        
      }
  }
  
  - (NSDate *)lastUnlocked {
      return [[NSUserDefaults standardUserDefaults] objectForKey:kPasscodeLastUnlocked];
  }
  
  - (void)resetLastUnlocked {
      NSDate *now = [[NSDate alloc] init];
      self.lastUnlocked = now;
      [now release];
  }
  
  - (void)setLastUnlocked:(NSDate *)lastUnlocked {
      [[NSUserDefaults standardUserDefaults] setObject:lastUnlocked forKey:kPasscodeLastUnlocked];
  }
  </code></pre>
  
  <p>Then, in a view controller that has <code>PasswordLock *passwordLock</code> as an instance variable, I want to do <code>passcode.immediate = NO</code>, but I get the error "Property 'immediate' not found on object of type 'PasscodeLock *'."</p>
  
  <p>How do I get <code>passcode.immediate = NO</code> to work?</p>