Permalink
Browse files

Modernize ObjC syntax.

[IMPROVED]  Migrate to modern ObjC syntax for type boxing.
  • Loading branch information...
1 parent 9d883b6 commit 792173474053e19500094d4a119a855c847a3c40 @lhunath lhunath committed Aug 19, 2012
@@ -24,10 +24,10 @@
if (!versionToAlgorithm)
versionToAlgorithm = [NSMutableDictionary dictionary];
- id<MPAlgorithm> algorithm = [versionToAlgorithm objectForKey:PearlUnsignedInteger(version)];
+ id<MPAlgorithm> algorithm = [versionToAlgorithm objectForKey:@(version)];
if (!algorithm)
if ((algorithm = [NSClassFromString(PearlString(@"MPAlgorithmV%u", version)) new]))
- [versionToAlgorithm setObject:algorithm forKey:PearlUnsignedInteger(version)];
+ [versionToAlgorithm setObject:algorithm forKey:@(version)];
return algorithm;
}
@@ -16,10 +16,8 @@ @implementation MPAppDelegate_Shared (Key)
static NSDictionary *keyQuery(MPUserEntity *user) {
return [PearlKeyChain createQueryForClass:kSecClassGenericPassword
- attributes:[NSDictionary dictionaryWithObjectsAndKeys:
- @"Saved Master Password", (__bridge id)kSecAttrService,
- user.name, (__bridge id)kSecAttrAccount,
- nil]
+ attributes:@{(__bridge id)kSecAttrService: @"Saved Master Password",
+ (__bridge id)kSecAttrAccount: user.name}
matches:nil];
}
@@ -81,7 +79,7 @@ - (void)signOutAnimated:(BOOL)animated {
if (self.activeUser) {
self.activeUser = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:MPNotificationSignedOut object:self userInfo:
- [NSDictionary dictionaryWithObject:PearlBool(animated) forKey:@"animated"]];
+ @{@"animated": @(animated)}];
}
}
@@ -62,8 +62,7 @@ - (UbiquityStoreManager *)storeManager {
localStoreURL:[[self applicationFilesDirectory] URLByAppendingPathComponent:@"MasterPassword.sqlite"]
containerIdentifier:@"HL3Q45LX9N.com.lyndir.lhunath.MasterPassword.shared"
#if TARGET_OS_IPHONE
- additionalStoreOptions:[NSDictionary dictionaryWithObject:NSFileProtectionComplete
- forKey:NSPersistentStoreFileProtectionKey]
+ additionalStoreOptions:@{NSPersistentStoreFileProtectionKey: NSFileProtectionComplete}
#else
additionalStoreOptions:nil
#endif
@@ -134,10 +133,9 @@ - (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didSwitchToiCloud:(
[TestFlight passCheckpoint:iCloudEnabled? MPCheckpointCloudEnabled: MPCheckpointCloudDisabled];
#endif
[[LocalyticsSession sharedLocalyticsSession] tagEvent:MPCheckpointCloud
- attributes:[NSDictionary dictionaryWithObject:iCloudEnabled? @"YES": @"NO"
- forKey:@"enabled"]];
+ attributes:@{@"enabled": iCloudEnabled? @"YES": @"NO"}];
- [MPConfig get].iCloud = [NSNumber numberWithBool:iCloudEnabled];
+ [MPConfig get].iCloud = @(iCloudEnabled);
}
- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didEncounterError:(NSError *)error cause:(UbiquityStoreManagerErrorCause)cause
@@ -312,7 +310,7 @@ - (MPImportResult)importSites:(NSString *)importedSitesString
dbg(@"Existing sites: %@", existingSites);
[elementsToDelete addObjectsFromArray:existingSites];
- [importedSiteElements addObject:[NSArray arrayWithObjects:lastUsed, uses, type, version, name, exportContent, nil]];
+ [importedSiteElements addObject:@[lastUsed, uses, type, version, name, exportContent]];
}
}
@@ -16,13 +16,11 @@ - (id)init {
if (!(self = [super init]))
return nil;
- [self.defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], NSStringFromSelector(@selector(askForReviews)),
+ [self.defaults registerDefaults:@{NSStringFromSelector(@selector(askForReviews)): @YES,
- [NSNumber numberWithBool:NO], NSStringFromSelector(@selector(rememberLogin)),
- [NSNumber numberWithBool:NO], NSStringFromSelector(@selector(iCloud)),
- [NSNumber numberWithBool:NO], NSStringFromSelector(@selector(iCloudDecided)),
- nil]];
+ NSStringFromSelector(@selector(rememberLogin)): @NO,
+ NSStringFromSelector(@selector(iCloud)): @NO,
+ NSStringFromSelector(@selector(iCloudDecided)): @NO}];
self.delegate = [MPAppDelegate get];
@@ -18,7 +18,7 @@ - (MPElementType)type {
- (void)setType:(MPElementType)aType {
- self.type_ = PearlUnsignedInteger(aType);
+ self.type_ = @(aType);
}
- (NSString *)typeName {
@@ -48,7 +48,7 @@ - (NSUInteger)uses {
- (void)setUses:(NSUInteger)anUses {
- self.uses_ = PearlUnsignedInteger(anUses);
+ self.uses_ = @(anUses);
}
- (NSUInteger)version {
@@ -58,7 +58,7 @@ - (NSUInteger)version {
- (void)setVersion:(NSUInteger)version {
- self.version_ = PearlUnsignedInteger(version);
+ self.version_ = @(version);
}
- (BOOL)requiresExplicitMigration {
@@ -68,7 +68,7 @@ - (BOOL)requiresExplicitMigration {
- (void)setRequiresExplicitMigration:(BOOL)requiresExplicitMigration {
- self.requiresExplicitMigration_ = PearlBool(requiresExplicitMigration);
+ self.requiresExplicitMigration_ = @(requiresExplicitMigration);
}
- (id<MPAlgorithm>)algorithm {
@@ -136,7 +136,7 @@ - (NSUInteger)counter {
- (void)setCounter:(NSUInteger)aCounter {
- self.counter_ = PearlUnsignedInteger(aCounter);
+ self.counter_ = @(aCounter);
}
- (id)content {
@@ -163,10 +163,8 @@ @implementation MPElementStoredEntity (MP)
+ (NSDictionary *)queryForDevicePrivateElementNamed:(NSString *)name {
return [PearlKeyChain createQueryForClass:kSecClassGenericPassword
- attributes:[NSDictionary dictionaryWithObjectsAndKeys:
- @"DevicePrivate", (__bridge id)kSecAttrService,
- name, (__bridge id)kSecAttrAccount,
- nil]
+ attributes:@{(__bridge id)kSecAttrService: @"DevicePrivate",
+ (__bridge id)kSecAttrAccount: name}
matches:nil];
}
@@ -268,7 +266,7 @@ - (NSUInteger)avatar {
- (void)setAvatar:(NSUInteger)anAvatar {
- self.avatar_ = PearlUnsignedInteger(anAvatar);
+ self.avatar_ = @(anAvatar);
}
- (BOOL)saveKey {
@@ -278,7 +276,7 @@ - (BOOL)saveKey {
- (void)setSaveKey:(BOOL)aSaveKey {
- self.saveKey_ = [NSNumber numberWithBool:aSaveKey];
+ self.saveKey_ = @(aSaveKey);
}
- (MPElementType)defaultType {
@@ -288,7 +286,7 @@ - (MPElementType)defaultType {
- (void)setDefaultType:(MPElementType)aDefaultType {
- self.defaultType_ = PearlUnsignedInteger(aDefaultType);
+ self.defaultType_ = @(aDefaultType);
}
- (BOOL)requiresExplicitMigration {
@@ -298,7 +296,7 @@ - (BOOL)requiresExplicitMigration {
- (void)setRequiresExplicitMigration:(BOOL)requiresExplicitMigration {
- self.requiresExplicitMigration_ = PearlBool(requiresExplicitMigration);
+ self.requiresExplicitMigration_ = @(requiresExplicitMigration);
}
- (NSString *)userID {
@@ -115,12 +115,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[PearlLogger get] registerListener:^BOOL(PearlLogMessage *message) {
if (message.level >= PearlLogLevelWarn)
[[LocalyticsSession sharedLocalyticsSession] tagEvent:@"Problem"
- attributes:[NSDictionary
- dictionaryWithObjectsAndKeys:
- [NSString stringWithCString:PearlLogLevelStr(message.level)
- encoding:NSASCIIStringEncoding], @"level",
- message.message, @"message",
- nil]];
+ attributes:@{@"level": @(PearlLogLevelStr(message.level)),
+ @"message": message.message}];
return YES;
}];
@@ -134,12 +130,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setTitleTextAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f], UITextAttributeTextColor,
- [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f], UITextAttributeTextShadowColor,
- [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
- [UIFont fontWithName:@"Exo-Bold" size:20.0f], UITextAttributeFont,
- nil]];
+ @{UITextAttributeTextColor: [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f],
+ UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f],
+ UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
+ UITextAttributeFont: [UIFont fontWithName:@"Exo-Bold" size:20.0f]}];
UIImage *navBarButton = [[UIImage imageNamed:@"ui_navbar_button"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
UIImage *navBarBack = [[UIImage imageNamed:@"ui_navbar_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
@@ -148,12 +142,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:navBarBack forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:nil forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearance] setTitleTextAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f], UITextAttributeTextColor,
- [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f], UITextAttributeTextShadowColor,
- [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
- [UIFont fontWithName:@"Helvetica-Neue" size:0.0f], UITextAttributeFont,
- nil]
+ @{UITextAttributeTextColor: [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f],
+ UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f],
+ UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
+ UITextAttributeFont: [UIFont fontWithName:@"Helvetica-Neue" size:0.0f]}
forState:UIControlStateNormal];
UIImage *toolBarImage = [[UIImage imageNamed:@"ui_toolbar_container"] resizableImageWithCapInsets:UIEdgeInsetsMake(25, 5, 5, 5)];
@@ -408,30 +400,25 @@ - (void)checkConfig {
[TestFlight passCheckpoint:MPCheckpointConfig];
[[LocalyticsSession sharedLocalyticsSession] tagEvent:MPCheckpointConfig attributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[MPConfig get].rememberLogin boolValue]
- ? @"YES": @"NO", @"rememberLogin",
- [[MPConfig get].iCloud boolValue]? @"YES"
- : @"NO", @"iCloud",
- [[MPConfig get].iCloudDecided boolValue]
- ? @"YES": @"NO", @"iCloudDecided",
- [[MPiOSConfig get].sendInfo boolValue]
- ? @"YES": @"NO", @"sendInfo",
- [[MPiOSConfig get].helpHidden boolValue]
- ? @"YES": @"NO", @"helpHidden",
- [[MPiOSConfig get].showQuickStart boolValue]
- ? @"YES": @"NO", @"showQuickStart",
- [[PearlConfig get].firstRun boolValue]
- ? @"YES": @"NO", @"firstRun",
- [[PearlConfig get].launchCount description],
- @"launchCount",
- [[PearlConfig get].askForReviews boolValue]
- ? @"YES": @"NO", @"askForReviews",
- [[PearlConfig get].reviewAfterLaunches description],
- @"reviewAfterLaunches",
- [PearlConfig get].reviewedVersion,
- @"reviewedVersion",
- nil]];
+ @{@"rememberLogin": [[MPConfig get].rememberLogin boolValue]
+ ? @"YES": @"NO",
+ @"iCloud": [[MPConfig get].iCloud boolValue]? @"YES"
+ : @"NO",
+ @"iCloudDecided": [[MPConfig get].iCloudDecided boolValue]
+ ? @"YES": @"NO",
+ @"sendInfo": [[MPiOSConfig get].sendInfo boolValue]
+ ? @"YES": @"NO",
+ @"helpHidden": [[MPiOSConfig get].helpHidden boolValue]
+ ? @"YES": @"NO",
+ @"showQuickStart": [[MPiOSConfig get].showQuickStart boolValue]
+ ? @"YES": @"NO",
+ @"firstRun": [[PearlConfig get].firstRun boolValue]
+ ? @"YES": @"NO",
+ @"launchCount": [[PearlConfig get].launchCount description],
+ @"askForReviews": [[PearlConfig get].askForReviews boolValue]
+ ? @"YES": @"NO",
+ @"reviewAfterLaunches": [[PearlConfig get].reviewAfterLaunches description],
+ @"reviewedVersion": [PearlConfig get].reviewedVersion}];
}
}
@@ -613,7 +600,7 @@ - (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didSwitchToiCloud:(
return;
}
- [MPConfig get].iCloudDecided = [NSNumber numberWithBool:YES];
+ [MPConfig get].iCloudDecided = @YES;
if (buttonIndex == [alert cancelButtonIndex])
return;
if (buttonIndex == [alert firstOtherButtonIndex] + 1)
@@ -43,7 +43,7 @@ - (void)viewWillDisappear:(BOOL)animated {
inf(@"Guide will disappear.");
[super viewWillDisappear:animated];
- [MPiOSConfig get].showQuickStart = [NSNumber numberWithBool:NO];
+ [MPiOSConfig get].showQuickStart = @NO;
}
- (void)viewDidUnload {
Oops, something went wrong.

0 comments on commit 7921734

Please sign in to comment.