From 6341270696e2361f5860bd5851fab07c2c86ab2c Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 28 Feb 2021 21:38:59 +0800 Subject: [PATCH] Coverts to Objective-C ARC. --- McBopomofo.xcodeproj/project.pbxproj | 2 + .../xcschemes/McBopomofoInstaller.xcscheme | 78 +++++++++++++++++++ Source/Installer/AppDelegate.h | 20 ++--- Source/Installer/AppDelegate.m | 17 +--- Source/Installer/ArchiveUtil.m | 12 +-- 5 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofoInstaller.xcscheme diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index bd16df99..f80b6d62 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -975,6 +975,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -1012,6 +1013,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; diff --git a/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofoInstaller.xcscheme b/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofoInstaller.xcscheme new file mode 100644 index 00000000..e47539ec --- /dev/null +++ b/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofoInstaller.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Installer/AppDelegate.h b/Source/Installer/AppDelegate.h index ebcf8b69..32b4936f 100644 --- a/Source/Installer/AppDelegate.h +++ b/Source/Installer/AppDelegate.h @@ -34,20 +34,20 @@ ArchiveUtil *_archiveUtil; NSString *_installingVersion; BOOL _upgrading; - NSButton *_installButton; - NSButton *_cancelButton; - NSTextView *_textView; - NSWindow *_progressSheet; - NSProgressIndicator *_progressIndicator; + NSButton *__weak _installButton; + NSButton *__weak _cancelButton; + NSTextView *__unsafe_unretained _textView; + NSWindow *__weak _progressSheet; + NSProgressIndicator *__weak _progressIndicator; NSDate *_translocationRemovalStartTime; NSInteger _currentVersionNumber; } - (IBAction)agreeAndInstallAction:(id)sender; - (IBAction)cancelAction:(id)sender; -@property (assign) IBOutlet NSButton *installButton; -@property (assign) IBOutlet NSButton *cancelButton; -@property (assign) IBOutlet NSTextView *textView; -@property (assign) IBOutlet NSWindow *progressSheet; -@property (assign) IBOutlet NSProgressIndicator *progressIndicator; +@property (weak) IBOutlet NSButton *installButton; +@property (weak) IBOutlet NSButton *cancelButton; +@property (unsafe_unretained) IBOutlet NSTextView *textView; +@property (weak) IBOutlet NSWindow *progressSheet; +@property (weak) IBOutlet NSProgressIndicator *progressIndicator; @end diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index 34887222..435e2c37 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -46,7 +46,6 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { [alert setInformativeText:message]; [alert addButtonWithTitle:buttonTitle]; [alert runModal]; - [alert autorelease]; } @implementation AppDelegate @@ -56,17 +55,10 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { @synthesize progressSheet = _progressSheet; @synthesize progressIndicator = _progressIndicator; -- (void)dealloc -{ - [_archiveUtil release]; - [_installingVersion release]; - [_translocationRemovalStartTime release]; - [super dealloc]; -} - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - _installingVersion = [[[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleVersionKey] retain]; + _installingVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleVersionKey]; NSString *versionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; _archiveUtil = [[ArchiveUtil alloc] initWithAppName:kTargetBin targetAppBundleName:kTargetBundle]; @@ -76,9 +68,9 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { [self.installButton setNextKeyView:self.cancelButton]; [[self window] setDefaultButtonCell:[self.installButton cell]]; - NSAttributedString *attrStr = [[[NSAttributedString alloc] initWithRTF:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"License" ofType:@"rtf"]] documentAttributes:NULL] autorelease]; + NSAttributedString *attrStr = [[NSAttributedString alloc] initWithRTF:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"License" ofType:@"rtf"]] documentAttributes:NULL]; - NSMutableAttributedString *mutableAttrStr = [[attrStr mutableCopy] autorelease]; + NSMutableAttributedString *mutableAttrStr = [attrStr mutableCopy]; [mutableAttrStr addAttribute:NSForegroundColorAttributeName value:[NSColor controlTextColor] range:NSMakeRange(0, [mutableAttrStr length])]; [[self.textView textStorage] setAttributedString:mutableAttrStr]; [self.textView setSelectedRange:NSMakeRange(0, 0)]; @@ -145,8 +137,7 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { }); }]; - [_translocationRemovalStartTime release]; - _translocationRemovalStartTime = [[NSDate date] retain]; + _translocationRemovalStartTime = [NSDate date]; [NSTimer scheduledTimerWithTimeInterval:kTranslocationRemovalTickInterval target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]; return; } diff --git a/Source/Installer/ArchiveUtil.m b/Source/Installer/ArchiveUtil.m index 2cd15003..90d47e35 100644 --- a/Source/Installer/ArchiveUtil.m +++ b/Source/Installer/ArchiveUtil.m @@ -28,16 +28,15 @@ targetAppBundleName:(NSString *)targetAppBundleName { self = [super init]; if (self) { - _appName = [name retain]; - _targetAppBundleName = [targetAppBundleName retain]; + _appName = name; + _targetAppBundleName = targetAppBundleName; } return self; } - (void)delloc { - [_appName release]; - [_targetAppBundleName release]; - [super dealloc]; + _appName = nil; + _targetAppBundleName = nil; } - (BOOL)validateIfNotarizedArchiveExists { @@ -67,7 +66,6 @@ devModeAppBundleExists]]; [alert addButtonWithTitle:@"Terminate"]; [alert runModal]; - [alert autorelease]; [[NSApplication sharedApplication] terminate:nil]; } else { @@ -84,8 +82,6 @@ devModeAppBundlePath]]; [alert addButtonWithTitle:@"Terminate"]; [alert runModal]; - [alert autorelease]; - [[NSApplication sharedApplication] terminate:nil]; }