I know that someone already asked about writing getter and setter for the variable BOOL . But, if I define custom methods getter and setter setImmediateand isImmediate, accordingly, I would like it to passcode.immediate = NOwork as well.
I don't have instance variables, but maybe I need one? I could add one for NSDate *lastUnlocked.
Here's the corresponding code:
extern NSString *const kPasscodeLastUnlocked;
@interface PasscodeLock : NSObject {
}
- (BOOL)isImmediate;
- (void)setImmediate:(BOOL)on;
- (NSDate *)lastUnlocked;
- (void)resetLastUnlocked;
- (void)setLastUnlocked:(NSDate *)lastUnlocked;
@end
#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];
}
Then in the view controller, which has PasswordLock *passwordLockas an instance variable, I want to do it passcode.immediate = NO, but I get the error "Property" immediate "could not be found on an object like" PasscodeLock *. "
How can I make it passcode.immediate = NOwork?