As descriped in the documentation I tried to bind some properties to the NSUserDefaults. Now I'm getting a EXC_BAD_ACCESS (code=2, address=0x10))
exception. What is wrong with the code?
@interface Settings:NSObject
@property (copy, nonatomic) NSString *username;
@property (copy, nonatomic) NSString *password;
@end
static NSString *const USERNAME_KEY = @"username";
static NSString *const PASSWORD_KEY = @"password";
@implementation Setting
{
NSUserDefaults *_defaults;
}
-(instancetype) init {
self = [super init];
if (self) {
_defaults = [NSUserDefaults standardUserDefaults];
RACChannelTo(self, username, @"") = [_defaults rac_channelTerminalForKey:USERNAME_KEY];
RACChannelTo(self, password, @"") = [_defaults rac_channelTerminalForKey:PASSWORD_KEY];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(defaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:nil];
}
return self;
}
The Exception is thrown in the class RACKVOTrampoline
in the method initWithTarget
on the line [self.target addObserver:self forKeyPath:self.keyPath options:options context:&RACKVOWrapperContext];
.