Using representedObject instead of custom property

This commit is contained in:
michael starke
2016-08-23 18:34:02 +02:00
parent 0f0e187bc8
commit d640434012
2 changed files with 7 additions and 7 deletions

View File

@@ -13,7 +13,6 @@
@property (copy, readonly) NSString *generatedPassword; @property (copy, readonly) NSString *generatedPassword;
@property (weak) id closeTarget; @property (weak) id closeTarget;
@property (nonatomic, weak) KPKEntry *entry;
@property (assign) BOOL allowsEntryDefaults; @property (assign) BOOL allowsEntryDefaults;
/** /**

View File

@@ -183,7 +183,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
} }
- (IBAction)_setDefault:(id)sender { - (IBAction)_setDefault:(id)sender {
if(self.useEntryDefaults && self.entry) { if(self.useEntryDefaults && self.representedObject) {
NSMutableDictionary *entryDefaults = [[self _currentEntryDefaults] mutableCopy]; NSMutableDictionary *entryDefaults = [[self _currentEntryDefaults] mutableCopy];
if(!entryDefaults) { if(!entryDefaults) {
entryDefaults = [[NSMutableDictionary alloc] initWithCapacity:4]; // we will only add one enty to new settings entryDefaults = [[NSMutableDictionary alloc] initWithCapacity:4]; // we will only add one enty to new settings
@@ -236,11 +236,11 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
} }
} }
- (void)setEntry:(KPKEntry *)entry { - (void)setRepresentedObject:(id)representedObject {
if(_entry != entry) { if(self.representedObject != representedObject) {
_entry = entry;
self.useEntryDefaults = [self _hasValidDefaultsForCurrentEntry]; self.useEntryDefaults = [self _hasValidDefaultsForCurrentEntry];
} }
[super setRepresentedObject:representedObject];
} }
- (void)setPassword:(NSString *)password { - (void)setPassword:(NSString *)password {
@@ -296,8 +296,9 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
} }
- (NSDictionary *)_currentEntryDefaults { - (NSDictionary *)_currentEntryDefaults {
if(self.entry) { if(self.representedObject) {
return [self _availableEntryDefaults][[self.entry.uuid UUIDString]]; NSAssert([self.representedObject isKindOfClass:[KPKEntry class]], @"Only KPKEntry as represented object supported!");
return [self _availableEntryDefaults][[self.representedObject uuid].UUIDString];
} }
return nil; return nil;
} }