From b0c9c31dc126aaef4fd45c40ee2766c5c2ec49c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 17 Jun 2014 02:44:03 +0100 Subject: [PATCH] Modern syntax --- NTSynchronousTask.m | 6 ++--- SUAppcast.h | 2 +- SUAppcast.m | 30 +++++++++++----------- SUAppcastItem.h | 6 ++--- SUAppcastItem.m | 48 +++++++++++++++++------------------ SUAutomaticUpdateAlert.h | 2 +- SUAutomaticUpdateAlert.m | 2 +- SUBasicUpdateDriver.m | 30 ++++++++++------------ SUBinaryDeltaApply.m | 6 ++--- SUBinaryDeltaCommon.m | 2 +- SUDiskImageUnarchiver.m | 4 +-- SUHost.h | 24 +++++++++--------- SUHost.m | 8 +++--- SUInstaller.m | 8 +++--- SUPackageInstaller.m | 10 ++++---- SUPipedUnarchiver.m | 12 ++++----- SUPlainInstaller.m | 18 ++++++------- SUPlainInstallerInternals.m | 22 ++++++++-------- SUStandardVersionComparator.m | 8 +++--- SUStatusController.h | 2 +- SUStatusController.m | 2 +- SUSystemProfiler.m | 24 +++++++++--------- SUUIBasedUpdateDriver.m | 2 +- SUUnarchiver_Private.h | 2 +- SUUnarchiver_Private.m | 2 +- SUUpdateAlert.h | 2 +- SUUpdateAlert.m | 4 +-- SUUpdateDriver.h | 6 ++--- SUUpdateDriver.m | 4 +-- SUUpdatePermissionPrompt.m | 2 +- SUUpdater.h | 24 +++++++----------- SUUpdater.m | 26 +++++++++---------- SUUpdater_Private.h | 2 +- SUWindowController.h | 2 +- SUWindowController.m | 2 +- finish_installation.m | 2 +- 36 files changed, 175 insertions(+), 183 deletions(-) diff --git a/NTSynchronousTask.m b/NTSynchronousTask.m index aaba1313..06ca7fea 100644 --- a/NTSynchronousTask.m +++ b/NTSynchronousTask.m @@ -32,7 +32,7 @@ - (void)taskOutputAvailable:(NSNotification*)note { - self.output = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem]; + self.output = [note userInfo][NSFileHandleNotificationDataItem]; self.done = YES; } @@ -42,7 +42,7 @@ self.result = [self.task terminationStatus]; } -- (id)init; +- (instancetype)init; { self = [super init]; if (self) @@ -94,7 +94,7 @@ name:NSTaskDidTerminateNotification object:[self task]]; - [[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, nil]]; + [[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:@[NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode]]; @try { diff --git a/SUAppcast.h b/SUAppcast.h index 71a04efe..7f835dd0 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -26,7 +26,7 @@ - (void)fetchAppcastFromURL:(NSURL *)url; -- (NSArray *)items; +@property (readonly, copy) NSArray *items; @end @protocol SUAppcastDelegate diff --git a/SUAppcast.m b/SUAppcast.m index 7473e931..b1999320 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -16,7 +16,7 @@ #import "SULog.h" @interface NSXMLElement (SUAppcastExtensions) -- (NSDictionary *)attributesAsDictionary; +@property (readonly, copy) NSDictionary *attributesAsDictionary; @end @implementation NSXMLElement (SUAppcastExtensions) @@ -26,7 +26,7 @@ NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; for (NSXMLNode *attribute in attributeEnum) { - [dictionary setObject:[attribute stringValue] forKey:[attribute name]]; + dictionary[[attribute name]] = [attribute stringValue]; } return dictionary; } @@ -142,11 +142,11 @@ NSString *name = [node name]; if (name) { - NSMutableArray *nodes = [nodesDict objectForKey:name]; + NSMutableArray *nodes = nodesDict[name]; if (nodes == nil) { nodes = [NSMutableArray array]; - [nodesDict setObject:nodes forKey:name]; + nodesDict[name] = nodes; } [nodes addObject:node]; } @@ -156,12 +156,12 @@ for (NSString *name in nodesDict) { - node = [self bestNodeInNodes:[nodesDict objectForKey:name]]; + node = [self bestNodeInNodes:nodesDict[name]]; if ([name isEqualToString:@"enclosure"]) { // enclosure is flattened as a separate dictionary for some reason NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary]; - [dict setObject:encDict forKey:@"enclosure"]; + dict[@"enclosure"] = encDict; } else if ([name isEqualToString:@"pubDate"]) @@ -169,7 +169,7 @@ // pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString NSDate *date = [NSDate dateWithNaturalLanguageString:[node stringValue]]; if (date) - [dict setObject:date forKey:name]; + dict[name] = date; } else if ([name isEqualToString:@"sparkle:deltas"]) { @@ -179,14 +179,14 @@ if ([[child name] isEqualToString:@"enclosure"]) [deltas addObject:[(NSXMLElement *)child attributesAsDictionary]]; } - [dict setObject:deltas forKey:@"deltas"]; + dict[@"deltas"] = deltas; } else if (name != nil) { // add all other values as strings NSString *theValue = [[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if (theValue != nil) { - [dict setObject:theValue forKey:name]; + dict[name] = theValue; } } } @@ -209,13 +209,13 @@ if ([appcastItems count]) { NSSortDescriptor *sort = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO] autorelease]; - [appcastItems sortUsingDescriptors:[NSArray arrayWithObject:sort]]; + [appcastItems sortUsingDescriptors:@[sort]]; self.items = appcastItems; } if (failed) { - [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]]; + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while parsing the update feed.", nil)}]]; } else if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)]) { @@ -243,7 +243,7 @@ { if ([delegate respondsToSelector:@selector(appcast:failedToLoadWithError:)]) { - [delegate appcast:self failedToLoadWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; + [delegate appcast:self failedToLoadWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]]; } } @@ -251,7 +251,7 @@ { // We use this method to pick out the localized version of a node when one's available. if ([nodes count] == 1) - return [nodes objectAtIndex:0]; + return nodes[0]; else if ([nodes count] == 0) return nil; @@ -262,11 +262,11 @@ lang = [[node attributeForName:@"xml:lang"] stringValue]; [languages addObject:(lang ? lang : @"")]; } - lang = [[NSBundle preferredLocalizationsFromArray:languages] objectAtIndex:0]; + lang = [NSBundle preferredLocalizationsFromArray:languages][0]; i = [languages indexOfObject:([languages containsObject:lang] ? lang : @"")]; if (i == NSNotFound) i = 0; - return [nodes objectAtIndex:i]; + return nodes[i]; } @end diff --git a/SUAppcastItem.h b/SUAppcastItem.h index b6695cef..dd740fd8 100644 --- a/SUAppcastItem.h +++ b/SUAppcastItem.h @@ -49,11 +49,11 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict; - (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString**)error; -- (BOOL)isDeltaUpdate; -- (BOOL)isCriticalUpdate; +@property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; +@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; // Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. -- (NSDictionary *)propertiesDictionary; +@property (readonly, copy) NSDictionary *propertiesDictionary; - (NSURL *)infoURL; // UK 2007-08-31 diff --git a/SUAppcastItem.m b/SUAppcastItem.m index 32097491..f66191c9 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -45,25 +45,25 @@ - (BOOL)isDeltaUpdate { - return [[propertiesDictionary objectForKey:@"enclosure"] objectForKey:@"sparkle:deltaFrom"] != nil; + return propertiesDictionary[@"enclosure"][@"sparkle:deltaFrom"] != nil; } - (BOOL)isCriticalUpdate { - return [[propertiesDictionary objectForKey:@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"]; + return [propertiesDictionary[@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"]; } -- initWithDictionary:(NSDictionary *)dict +- (instancetype) initWithDictionary:(NSDictionary *)dict { return [self initWithDictionary:dict failureReason:nil]; } -- initWithDictionary:(NSDictionary *)dict failureReason:(NSString**)error +- (instancetype) initWithDictionary:(NSDictionary *)dict failureReason:(NSString**)error { self = [super init]; if (self) { - id enclosure = [dict objectForKey:@"enclosure"]; + id enclosure = dict[@"enclosure"]; // Try to find a version string. // Finding the new version number from the RSS feed is a little bit hacky. There are two ways: @@ -73,14 +73,14 @@ // underscore and the last period as the version number. So name your packages like this: APPNAME_VERSION.extension. // The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle. // Feel free to change the separator string to a hyphen or something more suited to your needs if you like. - NSString *newVersion = [enclosure objectForKey:@"sparkle:version"]; + NSString *newVersion = enclosure[@"sparkle:version"]; if( newVersion == nil ) - newVersion = [dict objectForKey:@"sparkle:version"]; // UK 2007-08-31 Get version from the item, in case it's a download-less item (i.e. paid upgrade). + newVersion = dict[@"sparkle:version"]; // UK 2007-08-31 Get version from the item, in case it's a download-less item (i.e. paid upgrade). if (newVersion == nil) // no sparkle:version attribute anywhere? { // Separate the url by underscores and take the last component, as that'll be closest to the end, // then we remove the extension. Hopefully, this will be the version. - NSArray *fileComponents = [[enclosure objectForKey:@"url"] componentsSeparatedByString:@"_"]; + NSArray *fileComponents = [enclosure[@"url"] componentsSeparatedByString:@"_"]; if ([fileComponents count] > 1) newVersion = [[fileComponents lastObject] stringByDeletingPathExtension]; } @@ -94,11 +94,11 @@ } propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict]; - self.title = [dict objectForKey:@"title"]; - self.date = [dict objectForKey:@"pubDate"]; - self.itemDescription = [dict objectForKey:@"description"]; + self.title = dict[@"title"]; + self.date = dict[@"pubDate"]; + self.itemDescription = dict[@"description"]; - NSString* theInfoURL = [dict objectForKey:@"link"]; + NSString* theInfoURL = dict[@"link"]; if( theInfoURL ) { if( ![theInfoURL isKindOfClass: [NSString class]] ) @@ -117,7 +117,7 @@ return nil; } - NSString* enclosureURLString = [enclosure objectForKey:@"url"]; + NSString* enclosureURLString = enclosure[@"url"]; if( !enclosureURLString && !theInfoURL ) { if (error) @@ -131,15 +131,15 @@ self.fileURL = [NSURL URLWithString:fileURLString]; } if( enclosure ) - self.DSASignature = [enclosure objectForKey:@"sparkle:dsaSignature"]; + self.DSASignature = enclosure[@"sparkle:dsaSignature"]; self.versionString = newVersion; - self.minimumSystemVersion = [dict objectForKey:@"sparkle:minimumSystemVersion"]; - self.maximumSystemVersion = [dict objectForKey:@"sparkle:maximumSystemVersion"]; + self.minimumSystemVersion = dict[@"sparkle:minimumSystemVersion"]; + self.maximumSystemVersion = dict[@"sparkle:maximumSystemVersion"]; - NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"]; + NSString *shortVersionString = enclosure[@"sparkle:shortVersionString"]; if (nil == shortVersionString) - shortVersionString = [dict objectForKey:@"sparkle:shortVersionString"]; // fall back on the + shortVersionString = dict[@"sparkle:shortVersionString"]; // fall back on the if (shortVersionString) self.displayVersionString = shortVersionString; @@ -147,25 +147,25 @@ self.displayVersionString = [self versionString]; // Find the appropriate release notes URL. - if ([dict objectForKey:@"sparkle:releaseNotesLink"]) - self.releaseNotesURL = [NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]]; + if (dict[@"sparkle:releaseNotesLink"]) + self.releaseNotesURL = [NSURL URLWithString:dict[@"sparkle:releaseNotesLink"]]; else if ([self.itemDescription hasPrefix:@"http://"] || [self.itemDescription hasPrefix:@"https://"]) // if the description starts with http:// or https:// use that. self.releaseNotesURL = [NSURL URLWithString:self.itemDescription]; else self.releaseNotesURL = nil; - if ([dict objectForKey:@"deltas"]) + if (dict[@"deltas"]) { NSMutableDictionary *deltas = [NSMutableDictionary dictionary]; - NSArray *deltaDictionaries = [dict objectForKey:@"deltas"]; + NSArray *deltaDictionaries = dict[@"deltas"]; for (NSDictionary *deltaDictionary in [deltaDictionaries objectEnumerator]) { NSMutableDictionary *fakeAppCastDict = [dict mutableCopy]; [fakeAppCastDict removeObjectForKey:@"deltas"]; - [fakeAppCastDict setObject:deltaDictionary forKey:@"enclosure"]; + fakeAppCastDict[@"enclosure"] = deltaDictionary; SUAppcastItem *deltaItem = [[[self class] alloc] initWithDictionary:fakeAppCastDict]; [fakeAppCastDict release]; - [deltas setObject:deltaItem forKey:[deltaDictionary objectForKey:@"sparkle:deltaFrom"]]; + deltas[deltaDictionary[@"sparkle:deltaFrom"]] = deltaItem; [deltaItem release]; } self.deltaUpdates = deltas; diff --git a/SUAutomaticUpdateAlert.h b/SUAutomaticUpdateAlert.h index aacb4cf2..2c7cce65 100644 --- a/SUAutomaticUpdateAlert.h +++ b/SUAutomaticUpdateAlert.h @@ -27,7 +27,7 @@ typedef enum SUHost *host; } -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id)delegate; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id)delegate; - (IBAction)installNow:sender; - (IBAction)installLater:sender; - (IBAction)doNotInstall:sender; diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index 2a7c2afa..763e9b77 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -12,7 +12,7 @@ @implementation SUAutomaticUpdateAlert -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id)del +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id)del { self = [super initWithHost:aHost windowNibName:@"SUAutomaticUpdateAlert"]; if (self) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 50a25268..11a14932 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -37,7 +37,7 @@ [super checkForUpdatesAtURL:URL host:aHost]; if ([aHost isRunningOnReadOnlyVolume]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]]}]]; return; } @@ -125,7 +125,7 @@ } while (item && ![self hostSupportsItem:item]); if (binaryDeltaSupported()) { - SUAppcastItem *deltaUpdateItem = [[item deltaUpdates] objectForKey:[host version]]; + SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[host version]]; if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) { nonDeltaUpdateItem = [item retain]; item = deltaUpdateItem; @@ -164,7 +164,7 @@ [[updater delegate] updaterDidNotFindUpdate:updater]; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater]; - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]]}]]; } - (void)downloadUpdate @@ -194,7 +194,7 @@ { // Okay, something's really broken with this user's file structure. [download cancel]; - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir]}]]; } downloadPath = [[tempDir stringByAppendingPathComponent:name] retain]; @@ -224,7 +224,7 @@ - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]]; } - (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType @@ -273,7 +273,7 @@ return; } - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil)}]]; } - (BOOL)shouldInstallSynchronously { return NO; } @@ -289,7 +289,7 @@ #if !ENDANGER_USERS_WITH_INSECURE_UPDATES if (![self validateUpdateDownloadedToPath:downloadPath extractedToPath:tempDir DSASignature:[updateItem DSASignature] publicDSAKey:[host publicDSAKey]]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, @"The update is improperly signed.", NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: @"The update is improperly signed."}]]; return; } #endif @@ -327,12 +327,12 @@ NSString *targetPath = [[host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. NSError *error = nil; - [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: [NSDictionary dictionary] error: &error]; + [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: @{} error: &error]; if( [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error] ) relaunchPath = [targetPath retain]; else - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]}]]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; @@ -342,7 +342,7 @@ if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) { // Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin. - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [host name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [host name]], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath]}]]; // We intentionally don't abandon the update here so that the host won't initiate another. return; } @@ -351,14 +351,12 @@ if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; NSString *relaunchToolPath = [[relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS"] stringByAppendingPathComponent: finishInstallToolName]; - [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects: - [host bundlePath], + [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:@[[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", - showUI ? @"1" : @"0", - nil]]; + showUI ? @"1" : @"0"]]; [NSApp terminate:self]; } @@ -371,7 +369,7 @@ NSError * error = nil; success = [[NSFileManager defaultManager] removeItemAtPath: tempDir error: &error]; // Clean up the copied relauncher if( !success ) - [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[tempDir lastPathComponent]] tag:NULL]; + [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:@[[tempDir lastPathComponent]] tag:NULL]; } } @@ -380,7 +378,7 @@ if (aHost != host) { return; } NSError * dontThrow = nil; [[NSFileManager defaultManager] removeItemAtPath: relaunchPath error: &dontThrow]; // Clean up the copied relauncher - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]]; } - (void)abortUpdate diff --git a/SUBinaryDeltaApply.m b/SUBinaryDeltaApply.m index 46eea0c3..f19f76f3 100644 --- a/SUBinaryDeltaApply.m +++ b/SUBinaryDeltaApply.m @@ -40,11 +40,11 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil const char *value = 0; xar_subdoc_prop_get(subdoc, "before-sha1", &value); if (value) - expectedBeforeHash = [NSString stringWithUTF8String:value]; + expectedBeforeHash = @(value); xar_subdoc_prop_get(subdoc, "after-sha1", &value); if (value) - expectedAfterHash = [NSString stringWithUTF8String:value]; + expectedAfterHash = @(value); } } @@ -69,7 +69,7 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil xar_file_t file; xar_iter_t iter = xar_iter_new(); for (file = xar_file_first(x, iter); file; file = xar_file_next(iter)) { - NSString *path = [NSString stringWithUTF8String:xar_get_path(file)]; + NSString *path = @(xar_get_path(file)); NSString *sourceFilePath = [source stringByAppendingPathComponent:path]; NSString *destinationFilePath = [destination stringByAppendingPathComponent:path]; diff --git a/SUBinaryDeltaCommon.m b/SUBinaryDeltaCommon.m index 807ca083..ef88f9ce 100644 --- a/SUBinaryDeltaCommon.m +++ b/SUBinaryDeltaCommon.m @@ -150,7 +150,7 @@ NSString *hashOfTree(NSString *path) for (i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) sprintf(hexHash + i * 2, "%02x", hash[i]); - return [NSString stringWithUTF8String:hexHash]; + return @(hexHash); } void removeTree(NSString *path) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 60bc4aad..ddb27667 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -62,7 +62,7 @@ NSData *promptData = nil; promptData = [NSData dataWithBytes:"yes\n" length:4]; - NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen", nil]; + NSArray* arguments = @[@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen"]; NSData *output = nil; NSInteger taskResult = -1; @@ -139,7 +139,7 @@ reportError: finally: if (mountedSuccessfully) - [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]]; + [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; else SULog(@"Can't mount DMG %@",archivePath); [pool drain]; diff --git a/SUHost.h b/SUHost.h index bb1d5d43..3026dd86 100644 --- a/SUHost.h +++ b/SUHost.h @@ -21,18 +21,18 @@ + (NSString *)systemVersionString; -- (id)initWithBundle:(NSBundle *)aBundle; -- (NSString *)bundlePath; -- (NSString *)appSupportPath; -- (NSString *)installationPath; -- (NSString *)name; -- (NSString *)version; -- (NSString *)displayVersion; -- (NSImage *)icon; -- (BOOL)isRunningOnReadOnlyVolume; -- (BOOL)isBackgroundApplication; -- (NSString *)publicDSAKey; -- (NSArray *)systemProfile; +- (instancetype)initWithBundle:(NSBundle *)aBundle; +@property (readonly, copy) NSString *bundlePath; +@property (readonly, copy) NSString *appSupportPath; +@property (readonly, copy) NSString *installationPath; +@property (readonly, copy) NSString *name; +@property (readonly, copy) NSString *version; +@property (readonly, copy) NSString *displayVersion; +@property (readonly, copy) NSImage *icon; +@property (getter=isRunningOnReadOnlyVolume, readonly) BOOL runningOnReadOnlyVolume; +@property (getter=isBackgroundApplication, readonly) BOOL backgroundApplication; +@property (readonly, copy) NSString *publicDSAKey; +@property (readonly, copy) NSArray *systemProfile; - (id)objectForInfoDictionaryKey:(NSString *)key; - (BOOL)boolForInfoDictionaryKey:(NSString *)key; diff --git a/SUHost.m b/SUHost.m index d45a6185..c5c6caa5 100644 --- a/SUHost.m +++ b/SUHost.m @@ -19,7 +19,7 @@ @implementation SUHost @synthesize bundle; -- (id)initWithBundle:(NSBundle *)aBundle +- (instancetype)initWithBundle:(NSBundle *)aBundle { if ((self = [super init])) { @@ -62,7 +62,7 @@ appSupportPath = [@"~/Library/Application Support" stringByExpandingTildeInPath]; } else - appSupportPath = [appSupportPaths objectAtIndex:0]; + appSupportPath = appSupportPaths[0]; appSupportPath = [appSupportPath stringByAppendingPathComponent:[self name]]; appSupportPath = [appSupportPath stringByAppendingPathComponent:@".Sparkle"]; return appSupportPath; @@ -219,7 +219,7 @@ } else { - CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)[NSNumber numberWithBool:value], (CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)@(value), (CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); CFPreferencesSynchronize((CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); } } @@ -235,7 +235,7 @@ + (NSString *)systemVersionString { NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; - return [[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"]; + return [NSDictionary dictionaryWithContentsOfFile:versionPlistPath][@"ProductVersion"]; } @end diff --git a/SUInstaller.m b/SUInstaller.m index 7294ce50..dd02e6a3 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -124,7 +124,7 @@ static NSString* sUpdateFolder = nil; if (newAppDownloadPath == nil) { - [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate]; + [self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package."}] delegate:delegate]; } else { @@ -140,7 +140,7 @@ static NSString* sUpdateFolder = nil; NSTask *mdimport = [[[NSTask alloc] init] autorelease]; [mdimport setLaunchPath:@"/usr/bin/mdimport"]; - [mdimport setArguments:[NSArray arrayWithObject:installationPath]]; + [mdimport setArguments:@[installationPath]]; @try { [mdimport launch]; @@ -169,14 +169,14 @@ static NSString* sUpdateFolder = nil; else { if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)]) - [self performSelectorOnMainThread: @selector(notifyDelegateOfFailure:) withObject: [NSDictionary dictionaryWithObjectsAndKeys: host, SUNotifyDictHostKey, error, SUNotifyDictErrorKey, delegate, SUNotifyDictDelegateKey, nil] waitUntilDone: NO]; + [self performSelectorOnMainThread: @selector(notifyDelegateOfFailure:) withObject: @{SUNotifyDictHostKey: host, SUNotifyDictErrorKey: error, SUNotifyDictDelegateKey: delegate} waitUntilDone: NO]; } } +(void) notifyDelegateOfFailure: (NSDictionary*)dict { - [[dict objectForKey: SUNotifyDictDelegateKey] installerForHost: [dict objectForKey: SUNotifyDictHostKey] failedWithError: [dict objectForKey: SUNotifyDictErrorKey]]; + [dict[SUNotifyDictDelegateKey] installerForHost: dict[SUNotifyDictHostKey] failedWithError: dict[SUNotifyDictErrorKey]]; } @end diff --git a/SUPackageInstaller.m b/SUPackageInstaller.m index a7b1830a..8d9f163c 100644 --- a/SUPackageInstaller.m +++ b/SUPackageInstaller.m @@ -20,14 +20,14 @@ NSString *SUPackageInstallerInstallationPathKey = @"SUPackageInstallerInstallati + (void)finishInstallationWithInfo:(NSDictionary *)info { - [self finishInstallationToPath:[info objectForKey:SUPackageInstallerInstallationPathKey] withResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]]; + [self finishInstallationToPath:info[SUPackageInstallerInstallationPathKey] withResult:YES host:info[SUPackageInstallerHostKey] error:nil delegate:info[SUPackageInstallerDelegateKey]]; } + (void)performInstallationWithInfo:(NSDictionary *)info { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSTask *installer = [NSTask launchedTaskWithLaunchPath:[info objectForKey:SUPackageInstallerCommandKey] arguments:[info objectForKey:SUPackageInstallerArgumentsKey]]; + NSTask *installer = [NSTask launchedTaskWithLaunchPath:info[SUPackageInstallerCommandKey] arguments:info[SUPackageInstallerArgumentsKey]]; [installer waitUntilExit]; // Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine. @@ -46,16 +46,16 @@ NSString *SUPackageInstallerInstallationPathKey = @"SUPackageInstallerInstallati // -n = Open another instance if already open. // -b = app bundle identifier command = @"/usr/bin/open"; - args = [NSArray arrayWithObjects:@"-W", @"-n", @"-b", @"com.apple.installer", path, nil]; + args = @[@"-W", @"-n", @"-b", @"com.apple.installer", path]; if (![[NSFileManager defaultManager] fileExistsAtPath:command]) { - NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]]; + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!"}]; [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; } else { - NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, installationPath, SUPackageInstallerInstallationPathKey, nil]; + NSDictionary *info = @{SUPackageInstallerCommandKey: command, SUPackageInstallerArgumentsKey: args, SUPackageInstallerHostKey: host, SUPackageInstallerDelegateKey: delegate, SUPackageInstallerInstallationPathKey: installationPath}; if (synchronously) [self performInstallationWithInfo:info]; else diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index 705d7de4..b2f77bbe 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -17,16 +17,16 @@ { static NSDictionary *typeSelectorDictionary; if (!typeSelectorDictionary) - typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"extractZIP", @".zip", @"extractTAR", @".tar", - @"extractTGZ", @".tar.gz", @"extractTGZ", @".tgz", - @"extractTBZ", @".tar.bz2", @"extractTBZ", @".tbz", nil] retain]; + typeSelectorDictionary = [@{@".zip": @"extractZIP", @".tar": @"extractTAR", + @".tar.gz": @"extractTGZ", @".tgz": @"extractTGZ", + @".tar.bz2": @"extractTBZ", @".tbz": @"extractTBZ"} retain]; NSString *lastPathComponent = [path lastPathComponent]; for (id currentType in typeSelectorDictionary) { if ([currentType length] > [lastPathComponent length]) continue; if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType]) - return NSSelectorFromString([typeSelectorDictionary objectForKey:currentType]); + return NSSelectorFromString(typeSelectorDictionary[currentType]); } return NULL; } @@ -54,7 +54,7 @@ SULog(@"Extracting %@ using '%@'",archivePath,command); // Get the file size. - NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil] objectForKey:NSFileSize]; + NSNumber *fs = [[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil][NSFileSize]; if (fs == nil) goto reportError; // Thank you, Allan Odgaard! @@ -79,7 +79,7 @@ goto reportError; } - [self performSelectorOnMainThread:@selector(notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithUnsignedLong:len] waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(notifyDelegateOfExtractedLength:) withObject:@(len) waitUntilDone:NO]; } pclose(cmdFP); diff --git a/SUPlainInstaller.m b/SUPlainInstaller.m index 62675c8c..47065c3b 100644 --- a/SUPlainInstaller.m +++ b/SUPlainInstaller.m @@ -26,7 +26,7 @@ static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallati { // *** GETS CALLED ON NON-MAIN THREAD! - [self finishInstallationToPath:[info objectForKey:SUInstallerInstallationPathKey] withResult:[[info objectForKey:SUInstallerResultKey] boolValue] host:[info objectForKey:SUInstallerHostKey] error:[info objectForKey:SUInstallerErrorKey] delegate:[info objectForKey:SUInstallerDelegateKey]]; + [self finishInstallationToPath:info[SUInstallerInstallationPathKey] withResult:[info[SUInstallerResultKey] boolValue] host:info[SUInstallerHostKey] error:info[SUInstallerErrorKey] delegate:info[SUInstallerDelegateKey]]; } + (void)performInstallationWithInfo:(NSDictionary *)info @@ -37,9 +37,9 @@ static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallati NSError *error = nil; - NSString * oldPath = [[info objectForKey:SUInstallerHostKey] bundlePath]; - NSString * installationPath = [info objectForKey:SUInstallerInstallationPathKey]; - BOOL result = [self copyPathWithAuthentication:[info objectForKey:SUInstallerPathKey] overPath: installationPath temporaryName:[info objectForKey:SUInstallerTempNameKey] error:&error]; + NSString * oldPath = [info[SUInstallerHostKey] bundlePath]; + NSString * installationPath = info[SUInstallerInstallationPathKey]; + BOOL result = [self copyPathWithAuthentication:info[SUInstallerPathKey] overPath: installationPath temporaryName:info[SUInstallerTempNameKey] error:&error]; if( result ) { @@ -49,10 +49,10 @@ static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallati [self _movePathToTrash: oldPath]; // On success, trash old copy if there's still one due to renaming. } NSMutableDictionary *mutableInfo = [[info mutableCopy] autorelease]; - [mutableInfo setObject:[NSNumber numberWithBool:result] forKey:SUInstallerResultKey]; - [mutableInfo setObject:installationPath forKey:SUInstallerInstallationPathKey]; + mutableInfo[SUInstallerResultKey] = @(result); + mutableInfo[SUInstallerInstallationPathKey] = installationPath; if (!result && error) - [mutableInfo setObject:error forKey:SUInstallerErrorKey]; + mutableInfo[SUInstallerErrorKey] = error; [self performSelectorOnMainThread:@selector(finishInstallationWithInfo:) withObject:mutableInfo waitUntilDone:NO]; [pool drain]; @@ -65,7 +65,7 @@ static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallati if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedDescending) { NSString * errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]]; - NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{NSLocalizedDescriptionKey: errorMessage}]; [self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate]; return; } @@ -73,7 +73,7 @@ static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallati NSString *targetPath = [host installationPath]; NSString *tempName = [self temporaryNameForPath:targetPath]; - NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, targetPath, SUInstallerTargetPathKey, tempName, SUInstallerTempNameKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, installationPath, SUInstallerInstallationPathKey, nil]; + NSDictionary *info = @{SUInstallerPathKey: path, SUInstallerTargetPathKey: targetPath, SUInstallerTempNameKey: tempName, SUInstallerHostKey: host, SUInstallerDelegateKey: delegate, SUInstallerInstallationPathKey: installationPath}; if (synchronously) [self performInstallationWithInfo:info]; else diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index 8e9f410a..6bed7038 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -169,7 +169,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { NSString *errorMessage = [NSString stringWithFormat:@"Stat on %@ during authenticated file copy failed.", dst]; if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{NSLocalizedDescriptionKey: errorMessage}]; return NO; } } @@ -270,13 +270,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Something went wrong somewhere along the way, but we're not sure exactly where. NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file copy from %@ to %@ failed.", src, dst]; if (error != nil) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: errorMessage}]; } } else { if (error != nil) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate."}]; } return res; } @@ -343,13 +343,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Something went wrong somewhere along the way, but we're not sure exactly where. NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file move from %@ to %@ failed.", src, dst]; if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: errorMessage}]; } } else { if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate."}]; } return res; } @@ -391,13 +391,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Something went wrong somewhere along the way, but we're not sure exactly where. NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file remove from %@ failed.", src]; if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: errorMessage}]; } } else { if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate."}]; } return res; } @@ -417,7 +417,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { //SULog(@"Moving %@ to the trash.", path); NSInteger tag = 0; - if (![[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[path stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[path lastPathComponent]] tag:&tag]) + if (![[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[path stringByDeletingLastPathComponent] destination:@"" files:@[[path lastPathComponent]] tag:&tag]) { BOOL didFindTrash = NO; NSString* trashPath = [self _temporaryCopyNameForPath: path didFindTrash: &didFindTrash]; @@ -476,7 +476,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza if (!success && hadFileAtDest) { if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath]}]; return NO; } } @@ -492,7 +492,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza if( hadFileAtDest ) success = [manager moveItemAtPath:tmpPath toPath:dst error:error]; if (!success && error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath]}]; return NO; } @@ -556,7 +556,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Only recurse if it's actually a directory. Don't recurse into a // root-level symbolic link. NSDictionary* rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:root error:nil]; - NSString* rootType = [rootAttributes objectForKey:NSFileType]; + NSString* rootType = rootAttributes[NSFileType]; if (rootType == NSFileTypeDirectory) { // The NSDirectoryEnumerator will avoid recursing into any contained diff --git a/SUStandardVersionComparator.m b/SUStandardVersionComparator.m index f6f894c3..870bd53e 100644 --- a/SUStandardVersionComparator.m +++ b/SUStandardVersionComparator.m @@ -90,8 +90,8 @@ typedef enum { n = MIN([partsA count], [partsB count]); for (i = 0; i < n; ++i) { - partA = [partsA objectAtIndex:i]; - partB = [partsB objectAtIndex:i]; + partA = partsA[i]; + partB = partsB[i]; typeA = [self typeOfCharacter:partA]; typeB = [self typeOfCharacter:partB]; @@ -141,11 +141,11 @@ typedef enum { NSComparisonResult shorterResult, largerResult; if ([partsA count] > [partsB count]) { - missingPart = [partsA objectAtIndex:n]; + missingPart = partsA[n]; shorterResult = NSOrderedAscending; largerResult = NSOrderedDescending; } else { - missingPart = [partsB objectAtIndex:n]; + missingPart = partsB[n]; shorterResult = NSOrderedDescending; largerResult = NSOrderedAscending; } diff --git a/SUStatusController.h b/SUStatusController.h index b9f3082c..58fb35a4 100644 --- a/SUStatusController.h +++ b/SUStatusController.h @@ -27,7 +27,7 @@ @property (nonatomic) double maxProgressValue; @property (getter = isButtonEnabled) BOOL buttonEnabled; -- (id)initWithHost:(SUHost *)host; +- (instancetype)initWithHost:(SUHost *)host; // Pass 0 for the max progress value to get an indeterminate progress bar. // Pass nil for the status text to not show it. diff --git a/SUStatusController.m b/SUStatusController.m index d93bf065..1792e8e3 100644 --- a/SUStatusController.m +++ b/SUStatusController.m @@ -27,7 +27,7 @@ @synthesize buttonTitle; @synthesize host; -- (id)initWithHost:(SUHost *)aHost +- (instancetype)initWithHost:(SUHost *)aHost { self = [super initWithHost:aHost windowNibName:@"SUStatus"]; if (self) diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index 05d5e18d..758604e7 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -33,7 +33,7 @@ // Gather profile information and append it to the URL. NSMutableArray *profileArray = [NSMutableArray array]; - NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"displayKey", @"value", @"displayValue", nil]; + NSArray *profileDictKeys = @[@"key", @"displayKey", @"value", @"displayValue"]; int error = 0; int value = 0; size_t length = sizeof(value); @@ -41,7 +41,7 @@ // OS version NSString *currentSystemVersion = [SUHost systemVersionString]; if (currentSystemVersion != nil) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion,nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion] forKeys:profileDictKeys]]; // CPU type (decoder info for values found here is in mach/machine.h) error = sysctlbyname("hw.cputype", &value, &length, NULL, 0); @@ -54,7 +54,7 @@ case CPU_TYPE_POWERPC: visibleCPUType = @"PowerPC"; break; default: visibleCPUType = @"Unknown"; break; } - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cputype",@"CPU Type", [NSNumber numberWithInt:value], visibleCPUType,nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cputype",@"CPU Type", @(value), visibleCPUType] forKeys:profileDictKeys]]; } error = sysctlbyname("hw.cpu64bit_capable", &value, &length, NULL, 0); if(error != 0) @@ -66,7 +66,7 @@ if (error == 0) { is64bit = value == 1; - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpu64bit", @"CPU is 64-Bit?", [NSNumber numberWithBool:is64bit], is64bit ? @"Yes" : @"No", nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpu64bit", @"CPU is 64-Bit?", @(is64bit), is64bit ? @"Yes" : @"No"] forKeys:profileDictKeys]]; } error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0); if (error == 0) { @@ -85,7 +85,7 @@ } else { visibleCPUSubType = @"Other"; } - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpusubtype",@"CPU Subtype", [NSNumber numberWithInt:value], visibleCPUSubType,nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpusubtype",@"CPU Subtype", @(value), visibleCPUSubType] forKeys:profileDictKeys]]; } error = sysctlbyname("hw.model", NULL, &length, NULL, 0); if (error == 0) { @@ -93,11 +93,11 @@ if (cpuModel != NULL) { error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0); if (error == 0) { - NSString *rawModelName = [NSString stringWithUTF8String:cpuModel]; - NSString *visibleModelName = [modelTranslation objectForKey:rawModelName]; + NSString *rawModelName = @(cpuModel); + NSString *visibleModelName = modelTranslation[rawModelName]; if (visibleModelName == nil) visibleModelName = rawModelName; - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"model",@"Mac Model", rawModelName, visibleModelName] forKeys:profileDictKeys]]; } free(cpuModel); } @@ -106,21 +106,21 @@ // Number of CPUs error = sysctlbyname("hw.ncpu", &value, &length, NULL, 0); if (error == 0) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ncpu",@"Number of CPUs", [NSNumber numberWithInt:value], [NSNumber numberWithInt:value],nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"ncpu",@"Number of CPUs", @(value), @(value)] forKeys:profileDictKeys]]; // User preferred language NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defs objectForKey:@"AppleLanguages"]; if ([languages count] > 0) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"lang",@"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0],nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"lang",@"Preferred Language", languages[0], languages[0]] forKeys:profileDictKeys]]; // Application sending the request NSString *appName = [host name]; if (appName) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appName",@"Application Name", appName, appName,nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"appName",@"Application Name", appName, appName] forKeys:profileDictKeys]]; NSString *appVersion = [host version]; if (appVersion) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"appVersion",@"Application Version", appVersion, appVersion] forKeys:profileDictKeys]]; // Number of displays? diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index 073bf698..738b73b9 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -142,7 +142,7 @@ { NSDictionary * attributes; attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:nil]; - [statusController setMaxProgressValue:[[attributes objectForKey:NSFileSize] doubleValue]]; + [statusController setMaxProgressValue:[attributes[NSFileSize] doubleValue]]; } [statusController setProgressValue:[statusController progressValue] + (double)length]; } diff --git a/SUUnarchiver_Private.h b/SUUnarchiver_Private.h index 384edb7c..e2d66bd0 100644 --- a/SUUnarchiver_Private.h +++ b/SUUnarchiver_Private.h @@ -16,7 +16,7 @@ + (void)registerImplementation:(Class)implementation; + (NSArray *)unarchiverImplementations; + (BOOL)canUnarchivePath:(NSString *)path; -- (id)initWithPath:(NSString *)path host:(SUHost *)host; +- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host; - (void)notifyDelegateOfExtractedLength:(size_t)length; - (void)notifyDelegateOfSuccess; diff --git a/SUUnarchiver_Private.m b/SUUnarchiver_Private.m index da88bda6..862774c3 100644 --- a/SUUnarchiver_Private.m +++ b/SUUnarchiver_Private.m @@ -10,7 +10,7 @@ @implementation SUUnarchiver (Private) -- (id)initWithPath:(NSString *)path host:(SUHost *)host +- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host { if ((self = [super init])) { diff --git a/SUUpdateAlert.h b/SUUpdateAlert.h index e3ccf101..de38234e 100644 --- a/SUUpdateAlert.h +++ b/SUUpdateAlert.h @@ -39,7 +39,7 @@ typedef enum } @property (assign) id delegate; -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host; - (IBAction)installUpdate:sender; - (IBAction)skipThisVersion:sender; diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index 9ccf21a4..0edaf3fe 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -28,7 +28,7 @@ @implementation SUUpdateAlert @synthesize delegate; -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost { self = [super initWithHost:host windowNibName:@"SUUpdateAlert"]; if (self) @@ -203,7 +203,7 @@ #define DISTANCE_BETWEEN_BUTTON_GROUPS 12 CGFloat minimumWindowWidth = [[self window] frame].size.width -NSMaxX([installButton frame]) +NSMinX([skipButton frame]); // Distance between contents and left/right edge. - NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys: [installButton font], NSFontAttributeName, nil]; + NSDictionary* attrs = @{NSFontAttributeName: [installButton font]}; NSSize titleSize = [[installButton title] sizeWithAttributes: attrs]; titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit. NSRect installBtnBox = [installButton frame]; diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 4daecba9..7bbb542c 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -25,11 +25,11 @@ extern NSString * const SUUpdateDriverFinishedNotification; } @property (retain) SUHost *host; -- initWithUpdater:(SUUpdater *)updater; +- (instancetype) initWithUpdater:(SUUpdater *)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; -- (BOOL)isInterruptible; -- (BOOL)finished; +@property (getter=isInterruptible, readonly) BOOL interruptible; +@property (readonly) BOOL finished; @end diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index 0bc16963..924cc223 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -15,7 +15,7 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @synthesize host; -- initWithUpdater:(SUUpdater *)anUpdater +- (instancetype) initWithUpdater:(SUUpdater *)anUpdater { if ((self = [super init])) updater = anUpdater; @@ -32,7 +32,7 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; - (void)abortUpdate { - [self setValue:[NSNumber numberWithBool:YES] forKey:@"finished"]; + [self setValue:@YES forKey:@"finished"]; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self]; } diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index ad366103..a2bbffef 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -18,7 +18,7 @@ return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; } -- (id)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d +- (instancetype)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d { self = [super initWithHost:aHost windowNibName:@"SUUpdatePermissionPrompt"]; if (self) diff --git a/SUUpdater.h b/SUUpdater.h index 1f86f06e..e4fe1ac6 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -30,25 +30,19 @@ + (SUUpdater *)updaterForBundle:(NSBundle *)bundle; - (instancetype)initForBundle:(NSBundle *)bundle; -- (NSBundle *)hostBundle; +@property (readonly, strong) NSBundle *hostBundle; -- (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecks; -- (BOOL)automaticallyChecksForUpdates; +@property BOOL automaticallyChecksForUpdates; -- (void)setUpdateCheckInterval:(NSTimeInterval)interval; -- (NSTimeInterval)updateCheckInterval; +@property NSTimeInterval updateCheckInterval; -- (void)setFeedURL:(NSURL *)feedURL; -- (NSURL *)feedURL; // *** MUST BE CALLED ON MAIN THREAD *** +@property (copy) NSURL *feedURL; // *** MUST BE CALLED ON MAIN THREAD *** -- (void)setUserAgentString:(NSString *)userAgent; -- (NSString *)userAgentString; +@property (copy) NSString *userAgentString; -- (void)setSendsSystemProfile:(BOOL)sendsSystemProfile; -- (BOOL)sendsSystemProfile; +@property BOOL sendsSystemProfile; -- (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyDownloadsUpdates; -- (BOOL)automaticallyDownloadsUpdates; +@property (readonly) BOOL automaticallyDownloadsUpdates; // This IBAction is meant for a main menu item. Hook up any menu item to this action, // and Sparkle will check for updates and report back its findings verbosely. @@ -60,7 +54,7 @@ - (void)checkForUpdatesInBackground; // Date of last update check. Returns nil if no check has been performed. -- (NSDate*)lastUpdateCheckDate; +@property (readonly, copy) NSDate *lastUpdateCheckDate; // This begins a "probing" check for updates which will not actually offer to update to that version. The delegate methods, though, // (up to updater:didFindValidUpdate: and updaterDidNotFindUpdate:), are called, so you can use that information in your UI. @@ -69,7 +63,7 @@ // Call this to appropriately schedule or cancel the update checking timer according to the preferences for time interval and automatic checks. This call does not change the date of the next check, but only the internal NSTimer. - (void)resetUpdateCycle; -- (BOOL)updateInProgress; +@property (readonly) BOOL updateInProgress; @end diff --git a/SUUpdater.m b/SUUpdater.m index dc0135c6..1e7dfc39 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -29,15 +29,15 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @interface SUUpdater () @property (retain) NSTimer *checkTimer; -- (id)initForBundle:(NSBundle *)bundle; +- (instancetype)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; -- (BOOL)automaticallyDownloadsUpdates; +@property (readwrite) BOOL automaticallyDownloadsUpdates; - (void)scheduleNextUpdateCheck; - (void)registerAsObserver; - (void)unregisterAsObserver; - (void)updateDriverDidFinish:(NSNotification *)note; -- (NSURL *)parameterizedFeedURL; +@property (readonly, copy) NSURL *parameterizedFeedURL; -(void) notifyWillShowModalAlert; -(void) notifyDidShowModalAlert; @@ -62,14 +62,14 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault + (SUUpdater *)updaterForBundle:(NSBundle *)bundle { if (bundle == nil) bundle = [NSBundle mainBundle]; - id updater = [sharedUpdaters objectForKey:[NSValue valueWithNonretainedObject:bundle]]; + id updater = sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]]; if (updater == nil) updater = [[[[self class] alloc] initForBundle:bundle] autorelease]; return updater; } // This is the designated initializer for SUUpdater, important for subclasses -- (id)initForBundle:(NSBundle *)bundle +- (instancetype)initForBundle:(NSBundle *)bundle { self = [super init]; if (bundle == nil) bundle = [NSBundle mainBundle]; @@ -78,7 +78,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault if (self) [self registerAsObserver]; - id updater = [sharedUpdaters objectForKey:[NSValue valueWithNonretainedObject:bundle]]; + id updater = sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]]; if (updater) { [self release]; @@ -88,7 +88,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault { if (sharedUpdaters == nil) sharedUpdaters = [[NSMutableDictionary alloc] init]; - [sharedUpdaters setObject:self forKey:[NSValue valueWithNonretainedObject:bundle]]; + sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]] = self; host = [[SUHost alloc] initWithBundle:bundle]; #if !ENDANGER_USERS_WITH_INSECURE_UPDATES @@ -114,7 +114,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault // This will be used when the updater is instantiated in a nib such as MainMenu -- (id)init +- (instancetype)init { return [self initForBundle:[NSBundle mainBundle]]; } @@ -233,7 +233,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault -(void) putFeedURLIntoDictionary: (NSMutableDictionary*)theDict // You release this. { - [theDict setObject: [self feedURL] forKey: @"feedURL"]; + theDict[@"feedURL"] = [self feedURL]; } -(void) checkForUpdatesInBgReachabilityCheckWithDriver: (SUUpdateDriver*)inDriver /* RUNS ON ITS OWN THREAD */ @@ -253,7 +253,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault NSMutableDictionary* theDict = [NSMutableDictionary dictionary]; [self performSelectorOnMainThread: @selector(putFeedURLIntoDictionary:) withObject: theDict waitUntilDone: YES]; // Get feed URL on main thread, it's not safe to call elsewhere. - const char *hostname = [[[theDict objectForKey: @"feedURL"] host] cStringUsingEncoding: NSUTF8StringEncoding]; + const char *hostname = [[theDict[@"feedURL"] host] cStringUsingEncoding: NSUTF8StringEncoding]; SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, hostname); Boolean reachabilityResult = NO; // If the feed's using a file:// URL, we won't be able to use reachability. @@ -490,7 +490,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault const NSTimeInterval oneWeek = 60 * 60 * 24 * 7; sendingSystemProfile &= (-[lastSubmitDate timeIntervalSinceNow] >= oneWeek); - NSArray *parameters = [NSArray array]; + NSArray *parameters = @[]; if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]]; if (sendingSystemProfile) @@ -503,7 +503,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault // Build up the parameterized URL. NSMutableArray *parameterStrings = [NSMutableArray array]; for (NSDictionary *currentProfileInfo in parameters) - [parameterStrings addObject:[NSString stringWithFormat:@"%@=%@", [[[currentProfileInfo objectForKey:@"key"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [[[currentProfileInfo objectForKey:@"value"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [parameterStrings addObject:[NSString stringWithFormat:@"%@=%@", [[currentProfileInfo[@"key"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [[currentProfileInfo[@"value"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; NSString *separatorCharacter = @"?"; if ([baseFeedURL query]) @@ -516,7 +516,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault - (void)setUpdateCheckInterval:(NSTimeInterval)updateCheckInterval { - [host setObject:[NSNumber numberWithDouble:updateCheckInterval] forUserDefaultsKey:SUScheduledCheckIntervalKey]; + [host setObject:@(updateCheckInterval) forUserDefaultsKey:SUScheduledCheckIntervalKey]; if (updateCheckInterval == 0) // For compatibility with 1.1's settings. [self setAutomaticallyChecksForUpdates:NO]; [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; diff --git a/SUUpdater_Private.h b/SUUpdater_Private.h index 599ddfcd..40091549 100644 --- a/SUUpdater_Private.h +++ b/SUUpdater_Private.h @@ -10,6 +10,6 @@ @interface SUUpdater (Private) -- (BOOL)mayUpdateAndRestart; +@property (readonly) BOOL mayUpdateAndRestart; @end diff --git a/SUWindowController.h b/SUWindowController.h index fc50ba18..f3528bbc 100644 --- a/SUWindowController.h +++ b/SUWindowController.h @@ -14,7 +14,7 @@ @class SUHost; @interface SUWindowController : NSWindowController { } // We use this instead of plain old NSWindowController initWithWindowNibName so that we'll be able to find the right path when running in a bundle loaded from another app. -- (id)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName; +- (instancetype)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName; @end #endif diff --git a/SUWindowController.m b/SUWindowController.m index 038900ac..457fe1a5 100644 --- a/SUWindowController.m +++ b/SUWindowController.m @@ -11,7 +11,7 @@ @implementation SUWindowController -- (id)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName +- (instancetype)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName { NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:nibName ofType:@"nib"]; if (path == nil) // Slight hack to resolve issues with running Sparkle in debug configurations. diff --git a/finish_installation.m b/finish_installation.m index 06d7631c..6cde63be 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -39,7 +39,7 @@ @implementation TerminationListener -- (id) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath:(const char*)infolderpath shouldRelaunch:(BOOL)relaunch shouldShowUI:(BOOL)showUI selfPath:(NSString*)inSelfPath +- (instancetype) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath:(const char*)infolderpath shouldRelaunch:(BOOL)relaunch shouldShowUI:(BOOL)showUI selfPath:(NSString*)inSelfPath { if( !(self = [super init]) ) return nil;