From d6404340123eee7b7bfde249f100fcaa036028e1 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 23 Aug 2016 18:34:02 +0200 Subject: [PATCH] Using representedObject instead of custom property --- MacPass/MPPasswordCreatorViewController.h | 1 - MacPass/MPPasswordCreatorViewController.m | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MacPass/MPPasswordCreatorViewController.h b/MacPass/MPPasswordCreatorViewController.h index b444c87f..47b78552 100644 --- a/MacPass/MPPasswordCreatorViewController.h +++ b/MacPass/MPPasswordCreatorViewController.h @@ -13,7 +13,6 @@ @property (copy, readonly) NSString *generatedPassword; @property (weak) id closeTarget; -@property (nonatomic, weak) KPKEntry *entry; @property (assign) BOOL allowsEntryDefaults; /** diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index 0c6107f3..b6168b24 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -183,7 +183,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { } - (IBAction)_setDefault:(id)sender { - if(self.useEntryDefaults && self.entry) { + if(self.useEntryDefaults && self.representedObject) { NSMutableDictionary *entryDefaults = [[self _currentEntryDefaults] mutableCopy]; if(!entryDefaults) { 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 { - if(_entry != entry) { - _entry = entry; +- (void)setRepresentedObject:(id)representedObject { + if(self.representedObject != representedObject) { self.useEntryDefaults = [self _hasValidDefaultsForCurrentEntry]; } + [super setRepresentedObject:representedObject]; } - (void)setPassword:(NSString *)password { @@ -296,8 +296,9 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { } - (NSDictionary *)_currentEntryDefaults { - if(self.entry) { - return [self _availableEntryDefaults][[self.entry.uuid UUIDString]]; + if(self.representedObject) { + NSAssert([self.representedObject isKindOfClass:[KPKEntry class]], @"Only KPKEntry as represented object supported!"); + return [self _availableEntryDefaults][[self.representedObject uuid].UUIDString]; } return nil; }