From 4ad26db45b46d8267fcb5203571b81bc8949b853 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 03:01:19 +0100 Subject: Reformatting code for modern ObjC Replaced all [NSNumber numberWithBool:YES/NO] with the @YES/@NO literals. Also replaced some TRUE/FALSE with their YES/NO counterparts. --- Source/SPPreferencesUpgrade.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPPreferencesUpgrade.m') diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m index d4a9ca84..6151f675 100644 --- a/Source/SPPreferencesUpgrade.m +++ b/Source/SPPreferencesUpgrade.m @@ -76,7 +76,7 @@ void SPApplyRevisionChanges(void) } // Inform SPAppController to check installed default Bundles for available updates - [prefs setObject:[NSNumber numberWithBool:YES] forKey:@"doBundleUpdate"]; + [prefs setObject:@YES forKey:@"doBundleUpdate"]; // For versions prior to r336 (0.9.4), where column widths have been saved, walk through them and remove // any table widths set to 15 or less (fix for mangled columns caused by Issue #140) -- cgit v1.2.3 From 3cf0254e55d558565775e6cb20d36ea7e54beca1 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 03:12:41 +0100 Subject: Replace boxed integers in code with @ literals --- Source/SPPreferencesUpgrade.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/SPPreferencesUpgrade.m') diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m index 6151f675..a412088c 100644 --- a/Source/SPPreferencesUpgrade.m +++ b/Source/SPPreferencesUpgrade.m @@ -214,17 +214,17 @@ void SPApplyRevisionChanges(void) if ([[favorite objectForKey:@"host"] isEqualToString:@"localhost"] || ([favorite objectForKey:@"socket"] && [(NSString *)[favorite objectForKey:@"socket"] length])) { - [favorite setObject:[NSNumber numberWithInteger:1] forKey:@"type"]; + [favorite setObject:@1 forKey:@"type"]; // If SSH details are set, set to tunnel connection } else if ([favorite objectForKey:@"useSSH"] && [[favorite objectForKey:@"useSSH"] integerValue]) { - [favorite setObject:[NSNumber numberWithInteger:2] forKey:@"type"]; + [favorite setObject:@2 forKey:@"type"]; // Default to TCP/IP } else { - [favorite setObject:[NSNumber numberWithInteger:0] forKey:@"type"]; + [favorite setObject:@0 forKey:@"type"]; } // Remove SSH tunnel flag - no longer required @@ -311,7 +311,7 @@ void SPApplyRevisionChanges(void) NSNumber *newMappedValue = [encodingMap valueForKey:[prefs objectForKey:SPOldDefaultEncodingKey]]; - if (newMappedValue == nil) newMappedValue = [NSNumber numberWithInt:0]; + if (newMappedValue == nil) newMappedValue = @0; [prefs setObject:newMappedValue forKey:@"DefaultEncodingTag"]; } -- cgit v1.2.3 From 3b251b8e3d4dc9a694ef76562b388ab07da54785 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 19:48:41 +0100 Subject: Replace some NSDictionaries with literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [NSDictionary dictionary] → @{} * [NSDictionary dictionaryWithObject:forKey:] can safely be replaced. object==nil would have already thrown a NPE in the past. * Also replaced some (hopefully safe) NSArray initializers (ie. their objects should always exist). --- Source/SPPreferencesUpgrade.m | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'Source/SPPreferencesUpgrade.m') diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m index a412088c..d88dc4c8 100644 --- a/Source/SPPreferencesUpgrade.m +++ b/Source/SPPreferencesUpgrade.m @@ -130,22 +130,22 @@ void SPApplyRevisionChanges(void) if (recordedVersionNumber < 561) { NSEnumerator *keyEnumerator; NSString *oldKey, *newKey; - NSDictionary *keysToUpgrade = [NSDictionary dictionaryWithObjectsAndKeys: - @"encoding", SPDefaultEncoding, - @"useMonospacedFonts", SPUseMonospacedFonts, - @"reloadAfterAdding", SPReloadAfterAddingRow, - @"reloadAfterEditing", SPReloadAfterEditingRow, - @"reloadAfterRemoving", SPReloadAfterRemovingRow, - @"dontShowBlob", SPLoadBlobsAsNeeded, - @"fetchRowCount", @"FetchCorrectRowCount", - @"limitRows", SPLimitResults, - @"limitRowsValue", SPLimitResultsValue, - @"nullValue", SPNullValue, - @"showError", SPShowNoAffectedRowsError, - @"connectionTimeout", SPConnectionTimeoutValue, - @"keepAliveInterval", SPKeepAliveInterval, - @"lastFavoriteIndex", SPLastFavoriteID, - nil]; + NSDictionary *keysToUpgrade = @{ + SPDefaultEncoding : @"encoding", + SPUseMonospacedFonts : @"useMonospacedFonts", + SPReloadAfterAddingRow : @"reloadAfterAdding", + SPReloadAfterEditingRow : @"reloadAfterEditing", + SPReloadAfterRemovingRow : @"reloadAfterRemoving", + SPLoadBlobsAsNeeded : @"dontShowBlob", + @"FetchCorrectRowCount" : @"fetchRowCount", + SPLimitResults : @"limitRows", + SPLimitResultsValue : @"limitRowsValue", + SPNullValue : @"nullValue", + SPShowNoAffectedRowsError : @"showError", + SPConnectionTimeoutValue : @"connectionTimeout", + SPKeepAliveInterval : @"keepAliveInterval", + SPLastFavoriteID : @"lastFavoriteIndex" + }; keyEnumerator = [keysToUpgrade keyEnumerator]; @@ -255,7 +255,7 @@ void SPApplyRevisionChanges(void) if (([favorite isKindOfClass:[NSDictionary class]]) && ([favorite objectForKey:@"name"]) && ([favorite objectForKey:@"query"])) { NSMutableString *favoriteName = [NSMutableString stringWithString:[favorite objectForKey:@"name"]]; [favoriteName replaceOccurrencesOfString:@"\n" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [favoriteName length])]; - [queryFavoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithString:favoriteName], [favorite objectForKey:@"query"], nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; + [queryFavoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithString:favoriteName], [favorite objectForKey:@"query"], nil] forKeys:@[@"name", @"query"]]]; continue; } @@ -268,7 +268,7 @@ void SPApplyRevisionChanges(void) [favoriteName appendString:@"..."]; } - [queryFavoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithString:favoriteName], favorite, nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; + [queryFavoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithString:favoriteName], favorite, nil] forKeys:@[@"name", @"query"]]]; } [prefs setObject:queryFavoritesArray forKey:SPQueryFavorites]; @@ -287,27 +287,27 @@ void SPApplyRevisionChanges(void) // For versions prior to 2325 (<0.9.9), convert the old encoding pref string into the new localizable constant if (recordedVersionNumber < 2325 && [prefs objectForKey:SPOldDefaultEncodingKey] && [[prefs objectForKey:SPOldDefaultEncodingKey] isKindOfClass:[NSString class]]) { - NSDictionary *encodingMap = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt:SPEncodingAutodetect], @"Autodetect", - [NSNumber numberWithInt:SPEncodingUCS2], @"UCS-2 Unicode (ucs2)", - [NSNumber numberWithInt:SPEncodingUTF8], @"UTF-8 Unicode (utf8)", - [NSNumber numberWithInt:SPEncodingUTF8viaLatin1], @"UTF-8 Unicode via Latin 1", - [NSNumber numberWithInt:SPEncodingASCII], @"US ASCII (ascii)", - [NSNumber numberWithInt:SPEncodingLatin1], @"ISO Latin 1 (latin1)", - [NSNumber numberWithInt:SPEncodingMacRoman], @"Mac Roman (macroman)", - [NSNumber numberWithInt:SPEncodingCP1250Latin2], @"Windows Latin 2 (cp1250)", - [NSNumber numberWithInt:SPEncodingISOLatin2], @"ISO Latin 2 (latin2)", - [NSNumber numberWithInt:SPEncodingCP1256Arabic], @"Windows Arabic (cp1256)", - [NSNumber numberWithInt:SPEncodingGreek], @"ISO Greek (greek)", - [NSNumber numberWithInt:SPEncodingHebrew], @"ISO Hebrew (hebrew)", - [NSNumber numberWithInt:SPEncodingLatin5Turkish], @"ISO Turkish (latin5)", - [NSNumber numberWithInt:SPEncodingCP1257WinBaltic], @"Windows Baltic (cp1257)", - [NSNumber numberWithInt:SPEncodingCP1251WinCyrillic], @"Windows Cyrillic (cp1251)", - [NSNumber numberWithInt:SPEncodingBig5Chinese], @"Big5 Traditional Chinese (big5)", - [NSNumber numberWithInt:SPEncodingShiftJISJapanese], @"Shift-JIS Japanese (sjis)", - [NSNumber numberWithInt:SPEncodingEUCJPJapanese], @"EUC-JP Japanese (ujis)", - [NSNumber numberWithInt:SPEncodingEUCKRKorean], @"EUC-KR Korean (euckr)", - nil]; + NSDictionary *encodingMap = @{ + @"Autodetect" : @(SPEncodingAutodetect), + @"UCS-2 Unicode (ucs2)" : @(SPEncodingUCS2), + @"UTF-8 Unicode (utf8)" : @(SPEncodingUTF8), + @"UTF-8 Unicode via Latin 1" : @(SPEncodingUTF8viaLatin1), + @"US ASCII (ascii)" : @(SPEncodingASCII), + @"ISO Latin 1 (latin1)" : @(SPEncodingLatin1), + @"Mac Roman (macroman)" : @(SPEncodingMacRoman), + @"Windows Latin 2 (cp1250)" : @(SPEncodingCP1250Latin2), + @"ISO Latin 2 (latin2)" : @(SPEncodingISOLatin2), + @"Windows Arabic (cp1256)" : @(SPEncodingCP1256Arabic), + @"ISO Greek (greek)" : @(SPEncodingGreek), + @"ISO Hebrew (hebrew)" : @(SPEncodingHebrew), + @"ISO Turkish (latin5)" : @(SPEncodingLatin5Turkish), + @"Windows Baltic (cp1257)" : @(SPEncodingCP1257WinBaltic), + @"Windows Cyrillic (cp1251)" : @(SPEncodingCP1251WinCyrillic), + @"Big5 Traditional Chinese (big5)" : @(SPEncodingBig5Chinese), + @"Shift-JIS Japanese (sjis)" : @(SPEncodingShiftJISJapanese), + @"EUC-JP Japanese (ujis)" : @(SPEncodingEUCJPJapanese), + @"EUC-KR Korean (euckr)" : @(SPEncodingEUCKRKorean) + }; NSNumber *newMappedValue = [encodingMap valueForKey:[prefs objectForKey:SPOldDefaultEncodingKey]]; @@ -394,7 +394,7 @@ void SPMigrateConnectionFavoritesData(void) [prefs removeObjectForKey:@"LastFavoriteIndex"]; } - NSDictionary *newFavorites = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, favorites, SPFavoriteChildrenKey, nil] forKey:SPFavoritesRootKey]; + NSDictionary *newFavorites = @{SPFavoritesRootKey : [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, favorites, SPFavoriteChildrenKey, nil]}; error = nil; NSString *errorString = nil; -- cgit v1.2.3