From d861a1abec202bd25f0062e34a740aa604bcd20f Mon Sep 17 00:00:00 2001 From: Robert McGovern Date: Mon, 18 Apr 2022 12:43:58 +0100 Subject: [PATCH] Used Xcode's "Convert to Modern Objective-C syntax" --- FSUserDefaults/FSUserDefaults.h | 2 +- QuietUnrarAppDelegate.h | 2 +- QuietUnrarAppDelegate.m | 32 ++++++++++++++++---------------- TDNPreferencesWindowController.m | 16 ++++++++-------- TDNUnarchiver.m | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/FSUserDefaults/FSUserDefaults.h b/FSUserDefaults/FSUserDefaults.h index 581a72a..29f2058 100644 --- a/FSUserDefaults/FSUserDefaults.h +++ b/FSUserDefaults/FSUserDefaults.h @@ -43,6 +43,6 @@ @property (nonatomic, strong, readonly) NSUserDefaults *userDefaults; + (instancetype)sharedInstance; -- (instancetype)initWithSuiteName:(NSString *)suiteName; +- (instancetype)initWithSuiteName:(NSString *)suiteName NS_DESIGNATED_INITIALIZER; @end diff --git a/QuietUnrarAppDelegate.h b/QuietUnrarAppDelegate.h index 34e8305..fda39a2 100644 --- a/QuietUnrarAppDelegate.h +++ b/QuietUnrarAppDelegate.h @@ -41,6 +41,6 @@ enum - (BOOL) shouldFileBeReplaced:(NSString *) filename; - (void) alertUserOfMissing:(const char *) volume; - (void) hideDockIcon: (BOOL) hide; -- (NSString *) requestArchivePassword; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *requestArchivePassword; @end diff --git a/QuietUnrarAppDelegate.m b/QuietUnrarAppDelegate.m index 649175f..4b42e89 100644 --- a/QuietUnrarAppDelegate.m +++ b/QuietUnrarAppDelegate.m @@ -139,7 +139,7 @@ BOOL appRunning = NO; - (void)applicationWillBecomeActive:(NSNotification *)notification { //no use, if app is already running when I try and openfile it is my apps bundle id - NSLog(@"%@", [[NSWorkspace sharedWorkspace] frontmostApplication].bundleIdentifier); + NSLog(@"%@", [NSWorkspace sharedWorkspace].frontmostApplication.bundleIdentifier); } - (BOOL)application:(id)sender openFileWithoutUI:(NSString *)filename { @@ -168,10 +168,10 @@ BOOL appRunning = NO; NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"Overwrite"]; NSButton * skipButton = [alert addButtonWithTitle:@"Skip"]; - [skipButton setKeyEquivalent:@"\e"]; - [alert setMessageText:[NSString stringWithFormat:@"Overwrite %@?", filename]]; - [alert setInformativeText:[NSString stringWithFormat:@"The file %@ already exists. Do you wish to extract it again, overwriting the original file?", filename]]; - [alert setAlertStyle:NSAlertStyleWarning]; + skipButton.keyEquivalent = @"\e"; + alert.messageText = [NSString stringWithFormat:@"Overwrite %@?", filename]; + alert.informativeText = [NSString stringWithFormat:@"The file %@ already exists. Do you wish to extract it again, overwriting the original file?", filename]; + alert.alertStyle = NSAlertStyleWarning; if ([alert runModal] == NSAlertFirstButtonReturn) { result = YES; @@ -185,9 +185,9 @@ BOOL appRunning = NO; - (void) alertUserOfMissing:(const char *) volume { NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"OK"]; - [alert setMessageText:[NSString stringWithFormat:@"Archive part %s is missing.", volume]]; - [alert setInformativeText:@"Unable to extract all files from RAR archive as part of it is missing"]; - [alert setAlertStyle:NSAlertStyleCritical]; + alert.messageText = [NSString stringWithFormat:@"Archive part %s is missing.", volume]; + alert.informativeText = @"Unable to extract all files from RAR archive as part of it is missing"; + alert.alertStyle = NSAlertStyleCritical; [alert runModal]; @@ -202,7 +202,7 @@ BOOL appRunning = NO; [bundle loadNibNamed:@"PasswordView" owner:self topLevelObjects: nil]; } else { - [passwordField setStringValue:@""]; + passwordField.stringValue = @""; } NSString * password = nil; @@ -210,13 +210,13 @@ BOOL appRunning = NO; NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"OK"]; [alert addButtonWithTitle:@"Cancel"]; - [alert setMessageText:@"Archive Requires a password"]; - [alert setInformativeText:@"To extract the contents of this archive a password is required."]; - [alert setAccessoryView:passwordView]; - [alert setAlertStyle:NSAlertStyleWarning]; + alert.messageText = @"Archive Requires a password"; + alert.informativeText = @"To extract the contents of this archive a password is required."; + alert.accessoryView = passwordView; + alert.alertStyle = NSAlertStyleWarning; if ([alert runModal] == NSAlertFirstButtonReturn) { - password = [passwordField stringValue]; + password = passwordField.stringValue; } return password; @@ -241,7 +241,7 @@ BOOL appRunning = NO; if (show) { statusBarItem = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength]; statusBarItem.button.title = @"🎫"; //RMCG change to something more appropriate - [statusBarItem setMenu:[self makeStatusBarMenu]]; + statusBarItem.menu = [self makeStatusBarMenu]; } else { [NSStatusBar.systemStatusBar removeStatusItem:statusBarItem]; } @@ -249,7 +249,7 @@ BOOL appRunning = NO; - (NSMenu *) makeStatusBarMenu { NSMenu * statusBarMenu = [[NSMenu alloc] init]; - [statusBarMenu setTitle:@"QuietUnarchiver Menu"]; + statusBarMenu.title = @"QuietUnarchiver Menu"; NSMenuItem * preferencesMenuItem = [[NSMenuItem alloc] initWithTitle:@"Show Preferences" action:@selector(showPreferencesWindow) keyEquivalent:@""]; [statusBarMenu addItem:preferencesMenuItem]; diff --git a/TDNPreferencesWindowController.m b/TDNPreferencesWindowController.m index b98de0e..278dc80 100644 --- a/TDNPreferencesWindowController.m +++ b/TDNPreferencesWindowController.m @@ -24,7 +24,7 @@ @synthesize userDefaults, showNotificationsSwitch, playSoundSwitch, hideDockIconSwitch; @synthesize quietUnrar; -- (id) init { +- (instancetype) init { return [super initWithWindowNibName:@"PreferencesWindow"]; } @@ -34,31 +34,31 @@ userDefaults = [TDNUserDefaults sharedInstance]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. - [self.window setTitle:@"QuietUnarchiver Preferences"]; + (self.window).title = @"QuietUnarchiver Preferences"; if (userDefaults.hideDock) { - [hideDockIconSwitch setState:NSControlStateValueOn]; + hideDockIconSwitch.state = NSControlStateValueOn; } if (userDefaults.showNotification) { - [showNotificationsSwitch setState:NSControlStateValueOn]; + showNotificationsSwitch.state = NSControlStateValueOn; } if (userDefaults.playSounds) { - [playSoundSwitch setState:NSControlStateValueOn]; + playSoundSwitch.state = NSControlStateValueOn; } } - (IBAction)showNotificationsSwitchToggled:(id)sender { - userDefaults.showNotification = [showNotificationsSwitch state]; + userDefaults.showNotification = showNotificationsSwitch.state; } - (IBAction)playSoundSwitchToggled:(id)sender { - userDefaults.playSounds = [playSoundSwitch state]; + userDefaults.playSounds = playSoundSwitch.state; } - (IBAction)hideDockIconSwitchToggled:(id)sender { - userDefaults.hideDock = [hideDockIconSwitch state]; + userDefaults.hideDock = hideDockIconSwitch.state; [quietUnrar hideDockIcon: userDefaults.hideDock]; } diff --git a/TDNUnarchiver.m b/TDNUnarchiver.m index 976c90f..64fee7c 100644 --- a/TDNUnarchiver.m +++ b/TDNUnarchiver.m @@ -116,7 +116,7 @@ int CALLBACK generalCallbackFunction(UINT message, LPARAM userData, LPARAM param //Determine the folder we should extract the archive to. This by default //is the / - NSString * folderToExtractTo = [filename stringByDeletingPathExtension]; + NSString * folderToExtractTo = filename.stringByDeletingPathExtension; // Open the Archive for extraction, we set the open result to 3 so we can see it has changed char * filenameCString = (char *)[filename cStringUsingEncoding:NSISOLatin1StringEncoding]; @@ -202,7 +202,7 @@ int CALLBACK generalCallbackFunction(UINT message, LPARAM userData, LPARAM param } } - NSString * folderToExtractTo = [filename stringByDeletingPathExtension]; + NSString * folderToExtractTo = filename.stringByDeletingPathExtension; BOOL extractFilesSuccessful = [archive extractFilesTo: folderToExtractTo overwrite:NO