From b67132671afaa339a40b5867b9a15813d91061c5 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 27 Sep 2013 21:23:52 -0400 Subject: [PATCH] Modernized Obj-C syntax. [UPDATED] Modernized Obj-C syntax. --- External/Pearl | 2 +- External/UbiquityStoreManager | 2 +- MasterPassword/ObjC/MPAlgorithm.m | 4 ++-- MasterPassword/ObjC/MPAlgorithmV0.m | 2 +- MasterPassword/ObjC/MPAlgorithmV1.m | 2 +- MasterPassword/ObjC/MPAppDelegate_Store.m | 12 ++++++------ MasterPassword/ObjC/iOS/MPAppsViewController.m | 8 ++++---- .../ObjC/iOS/MPElementListAllViewController.m | 10 +++++----- MasterPassword/ObjC/iOS/MPLogsViewController.m | 4 ++-- MasterPassword/ObjC/iOS/MPMainViewController.m | 4 ++-- MasterPassword/ObjC/iOS/MPUnlockViewController.m | 16 ++++++++-------- MasterPassword/ObjC/iOS/MPiOSAppDelegate.m | 4 ++-- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/External/Pearl b/External/Pearl index 00b732f8..fb1b46e2 160000 --- a/External/Pearl +++ b/External/Pearl @@ -1 +1 @@ -Subproject commit 00b732f8b73035b81c4abd763ee2a7e54f6ad3c5 +Subproject commit fb1b46e2b4f2e661f84521ce243d31a10aa9cee7 diff --git a/External/UbiquityStoreManager b/External/UbiquityStoreManager index 7fb753f0..4834f69d 160000 --- a/External/UbiquityStoreManager +++ b/External/UbiquityStoreManager @@ -1 +1 @@ -Subproject commit 7fb753f0f84afdb5607332b586f1345d9a2ae1a1 +Subproject commit 4834f69d55b7cd84d719869336ba213ecc456542 diff --git a/MasterPassword/ObjC/MPAlgorithm.m b/MasterPassword/ObjC/MPAlgorithm.m index bf9062bc..8d557278 100644 --- a/MasterPassword/ObjC/MPAlgorithm.m +++ b/MasterPassword/ObjC/MPAlgorithm.m @@ -23,9 +23,9 @@ id MPAlgorithmForVersion(NSUInteger version) { if (!versionToAlgorithm) versionToAlgorithm = [NSMutableDictionary dictionary]; - id algorithm = [versionToAlgorithm objectForKey:@(version)]; + id algorithm = versionToAlgorithm[@(version)]; if (!algorithm) if ((algorithm = [NSClassFromString( PearlString( @"MPAlgorithmV%lu", (unsigned long)version ) ) new])) - [versionToAlgorithm setObject:algorithm forKey:@(version)]; + versionToAlgorithm[@(version)] = algorithm; return algorithm; } diff --git a/MasterPassword/ObjC/MPAlgorithmV0.m b/MasterPassword/ObjC/MPAlgorithmV0.m index abdcd46d..40e746de 100644 --- a/MasterPassword/ObjC/MPAlgorithmV0.m +++ b/MasterPassword/ObjC/MPAlgorithmV0.m @@ -229,7 +229,7 @@ NSAssert([seed length], @"Missing seed."); NSArray *typeCiphers = [[MPTypes_ciphers valueForKey:[self classNameOfType:type]] valueForKey:[self nameOfType:type]]; - NSString *cipher = [typeCiphers objectAtIndex:htons(seedBytes[0]) % [typeCiphers count]]; + NSString *cipher = typeCiphers[htons(seedBytes[0]) % [typeCiphers count]]; trc(@"type %@, ciphers: %@, selected: %@", [self nameOfType:type], typeCiphers, cipher); // Encode the content, character by character, using subsequent seed bytes and the cipher. diff --git a/MasterPassword/ObjC/MPAlgorithmV1.m b/MasterPassword/ObjC/MPAlgorithmV1.m index b7b8fa42..6b0f0028 100644 --- a/MasterPassword/ObjC/MPAlgorithmV1.m +++ b/MasterPassword/ObjC/MPAlgorithmV1.m @@ -70,7 +70,7 @@ // Determine the cipher from the first seed byte. NSAssert([seed length], @"Missing seed."); NSArray *typeCiphers = [[MPTypes_ciphers valueForKey:[self classNameOfType:type]] valueForKey:[self nameOfType:type]]; - NSString *cipher = [typeCiphers objectAtIndex:seedBytes[0] % [typeCiphers count]]; + NSString *cipher = typeCiphers[seedBytes[0] % [typeCiphers count]]; trc(@"type %@, ciphers: %@, selected: %@", [self nameOfType:type], typeCiphers, cipher); // Encode the content, character by character, using subsequent seed bytes and the cipher. diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.m b/MasterPassword/ObjC/MPAppDelegate_Store.m index 0a4ce5a5..cfe3df93 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.m +++ b/MasterPassword/ObjC/MPAppDelegate_Store.m @@ -608,12 +608,12 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext, // Import new sites. for (NSArray *siteElements in importedSiteElements) { - NSDate *lastUsed = [[NSDateFormatter rfc3339DateFormatter] dateFromString:[siteElements objectAtIndex:0]]; - NSUInteger uses = (unsigned)[[siteElements objectAtIndex:1] integerValue]; - MPElementType type = (MPElementType)[[siteElements objectAtIndex:2] integerValue]; - NSUInteger version = (unsigned)[[siteElements objectAtIndex:3] integerValue]; - NSString *name = [siteElements objectAtIndex:4]; - NSString *exportContent = [siteElements objectAtIndex:5]; + NSDate *lastUsed = [[NSDateFormatter rfc3339DateFormatter] dateFromString:siteElements[0]]; + NSUInteger uses = (unsigned)[siteElements[1] integerValue]; + MPElementType type = (MPElementType)[siteElements[2] integerValue]; + NSUInteger version = (unsigned)[siteElements[3] integerValue]; + NSString *name = siteElements[4]; + NSString *exportContent = siteElements[5]; // Create new site. MPElementEntity diff --git a/MasterPassword/ObjC/iOS/MPAppsViewController.m b/MasterPassword/ObjC/iOS/MPAppsViewController.m index 5406aa6a..0b9f2eb9 100644 --- a/MasterPassword/ObjC/iOS/MPAppsViewController.m +++ b/MasterPassword/ObjC/iOS/MPAppsViewController.m @@ -64,7 +64,7 @@ [UIApp setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; MPCheckpoint( MPCheckpointApps, nil ); - [self.pageViewController setViewControllers:@[ [self.pageVCs objectAtIndex:1] ] direction:UIPageViewControllerNavigationDirectionForward + [self.pageViewController setViewControllers:@[ (self.pageVCs)[1] ] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; [super viewWillAppear:animated]; @@ -76,7 +76,7 @@ [[LocalyticsSession sharedLocalyticsSession] tagScreen:@"Apps"]; #endif - [self.pageViewController setViewControllers:@[ [self.pageVCs objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward + [self.pageViewController setViewControllers:@[ (self.pageVCs)[0] ] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; [super viewDidAppear:animated]; @@ -103,14 +103,14 @@ viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger vcIndex = [self.pageVCs indexOfObject:viewController]; - return [self.pageVCs objectAtIndex:(vcIndex + [self.pageVCs count] - 1) % self.pageVCs.count]; + return (self.pageVCs)[(vcIndex + [self.pageVCs count] - 1) % self.pageVCs.count]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger vcIndex = [self.pageVCs indexOfObject:viewController]; - return [self.pageVCs objectAtIndex:(vcIndex + 1) % self.pageVCs.count]; + return (self.pageVCs)[(vcIndex + 1) % self.pageVCs.count]; } - (IBAction)exit { diff --git a/MasterPassword/ObjC/iOS/MPElementListAllViewController.m b/MasterPassword/ObjC/iOS/MPElementListAllViewController.m index 2fdb1333..971d7310 100644 --- a/MasterPassword/ObjC/iOS/MPElementListAllViewController.m +++ b/MasterPassword/ObjC/iOS/MPElementListAllViewController.m @@ -117,10 +117,10 @@ id newContent = [element.algorithm resolveContentForElement:element usingKey:key]; if (!(element.type & MPElementFeatureDevicePrivate) && (!oldContent || ![oldContent isEqual:newContent])) - [elementChanges setObject:@{ + elementChanges[element.name] = @{ MPElementUpgradeOldContentKey : oldContent, MPElementUpgradeNewContentKey : newContent, - } forKey:element.name]; + }; } [moc saveToStore]; @@ -135,9 +135,9 @@ NSMutableString *formattedChanges = [NSMutableString new]; for (NSString *changedElementName in changes) { - NSDictionary *elementChanges = [changes objectForKey:changedElementName]; - id oldContent = [elementChanges objectForKey:MPElementUpgradeOldContentKey]; - id newContent = [elementChanges objectForKey:MPElementUpgradeNewContentKey]; + NSDictionary *elementChanges = changes[changedElementName]; + id oldContent = elementChanges[MPElementUpgradeOldContentKey]; + id newContent = elementChanges[MPElementUpgradeNewContentKey]; [formattedChanges appendFormat:@"%@: %@ -> %@\n", changedElementName, oldContent, newContent]; } diff --git a/MasterPassword/ObjC/iOS/MPLogsViewController.m b/MasterPassword/ObjC/iOS/MPLogsViewController.m index 560ee866..a4b41974 100644 --- a/MasterPassword/ObjC/iOS/MPLogsViewController.m +++ b/MasterPassword/ObjC/iOS/MPLogsViewController.m @@ -88,7 +88,7 @@ NSFetchRequest *sitesFetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )]; for (NSURL *cloudStoreURL in cloudStores) { NSString *storeUUID = [[cloudStoreURL URLByDeletingPathExtension] lastPathComponent]; - for (NSDictionary *cloudStoreOptions in [cloudStores objectForKey:cloudStoreURL]) { + for (NSDictionary *cloudStoreOptions in cloudStores[cloudStoreURL]) { NSError *error = nil; NSPersistentStore *store = nil; NSUInteger firstDash = [storeUUID rangeOfString:@"-" options:0].location; @@ -127,7 +127,7 @@ storePSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; } - [stores setObject:cloudStoreOptions forKey:storeDescription]; + stores[storeDescription] = cloudStoreOptions; } } } diff --git a/MasterPassword/ObjC/iOS/MPMainViewController.m b/MasterPassword/ObjC/iOS/MPMainViewController.m index 2332cf4c..093c35fb 100644 --- a/MasterPassword/ObjC/iOS/MPMainViewController.m +++ b/MasterPassword/ObjC/iOS/MPMainViewController.m @@ -94,7 +94,7 @@ [[NSNotificationCenter defaultCenter] addObserverForName:MPSignedOutNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock: ^(NSNotification *note) { - BOOL animated = [[note.userInfo objectForKey:@"animated"] boolValue]; + BOOL animated = [(note.userInfo)[@"animated"] boolValue]; _activeElementOID = nil; self.suppressOutdatedAlert = NO; @@ -294,7 +294,7 @@ - (void)toggleUserAnimated:(BOOL)animated { - [MPiOSConfig get].siteInfoHidden = PearlBool(!self.siteInfoHidden); + [MPiOSConfig get].siteInfoHidden = @(!self.siteInfoHidden); self.siteInfoHidden = [[MPiOSConfig get].siteInfoHidden boolValue]; [self updateUserHiddenAnimated:animated]; } diff --git a/MasterPassword/ObjC/iOS/MPUnlockViewController.m b/MasterPassword/ObjC/iOS/MPUnlockViewController.m index 57202d71..7ce93ea4 100644 --- a/MasterPassword/ObjC/iOS/MPUnlockViewController.m +++ b/MasterPassword/ObjC/iOS/MPUnlockViewController.m @@ -365,7 +365,7 @@ } options:0]; - [self.avatarToUserOID setObject:NilToNSNull([user objectID]) forKey:[NSValue valueWithNonretainedObject:avatar]]; + (self.avatarToUserOID)[[NSValue valueWithNonretainedObject:avatar]] = NilToNSNull([user objectID]); if ([_selectedUserOID isEqual:[user objectID]]) avatar.selected = YES; @@ -625,7 +625,7 @@ - (void)initializeWordLabel:(UILabel *)wordLabel { wordLabel.alpha = 0.05 + (random() % 35) / 100.0F; - wordLabel.text = [self.wordList objectAtIndex:(NSUInteger)random() % [self.wordList count]]; + wordLabel.text = (self.wordList)[(NSUInteger)random() % [self.wordList count]]; } - (void)setPasswordTip:(NSString *)string { @@ -686,7 +686,7 @@ - (MPUserEntity *)userForAvatar:(UIButton *)avatar inContext:(NSManagedObjectContext *)context { - NSManagedObjectID *userOID = NSNullToNil([self.avatarToUserOID objectForKey:[NSValue valueWithNonretainedObject:avatar]]); + NSManagedObjectID *userOID = NSNullToNil((self.avatarToUserOID)[[NSValue valueWithNonretainedObject:avatar]]); if (!userOID) return nil; @@ -707,7 +707,7 @@ if (active) { rotate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; - rotate.fromValue = [NSNumber numberWithFloat:0]; + rotate.fromValue = @0.0; rotate.repeatCount = MAXFLOAT; } else { @@ -741,12 +741,12 @@ toShadowColorAnimation.fillMode = kCAFillModeForwards; CABasicAnimation *toShadowOpacityAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; - toShadowOpacityAnimation.toValue = PearlFloat(0.2); + toShadowOpacityAnimation.toValue = @0.2f; toShadowOpacityAnimation.duration = 0.5f; CABasicAnimation *pulseShadowOpacityAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; - pulseShadowOpacityAnimation.fromValue = PearlFloat(0.2); - pulseShadowOpacityAnimation.toValue = PearlFloat(0.6); + pulseShadowOpacityAnimation.fromValue = @0.2f; + pulseShadowOpacityAnimation.toValue = @0.6f; pulseShadowOpacityAnimation.beginTime = 0.5f; pulseShadowOpacityAnimation.duration = 2.0f; pulseShadowOpacityAnimation.autoreverses = YES; @@ -767,7 +767,7 @@ toShadowColorAnimation.duration = 0.5f; CABasicAnimation *toShadowOpacityAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; - toShadowOpacityAnimation.toValue = PearlFloat(1); + toShadowOpacityAnimation.toValue = @1.0f; toShadowOpacityAnimation.duration = 0.5f; CAAnimationGroup *group = [[CAAnimationGroup alloc] init]; diff --git a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m index a5620ff5..914caf8b 100644 --- a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m +++ b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m @@ -33,8 +33,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @try { - [[[NSBundle mainBundle] mutableInfoDictionary] setObject:@"Master Password" forKey:@"CFBundleDisplayName"]; - [[[NSBundle mainBundle] mutableLocalizedInfoDictionary] setObject:@"Master Password" forKey:@"CFBundleDisplayName"]; + [[NSBundle mainBundle] mutableInfoDictionary][@"CFBundleDisplayName"] = @"Master Password"; + [[NSBundle mainBundle] mutableLocalizedInfoDictionary][@"CFBundleDisplayName"] = @"Master Password"; #ifdef TESTFLIGHT_SDK_VERSION NSString *testFlightToken = [self testFlightToken];