Merge pull request #194 from 0xced/clean-optional-delegate-calls

Remove unnecessary nil checking before calling `respondsToSelector:`
This commit is contained in:
Andreas Linde 2015-09-09 13:13:00 +02:00
commit ff397e876b
6 changed files with 29 additions and 40 deletions

View File

@ -596,8 +596,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
} }
#endif #endif
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userIDForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userIDForHockeyManager:componentManager:)]) {
userID = [[BITHockeyManager sharedHockeyManager].delegate userID = [[BITHockeyManager sharedHockeyManager].delegate
userIDForHockeyManager:[BITHockeyManager sharedHockeyManager] userIDForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self] ?: @""; componentManager:self] ?: @"";
@ -615,14 +614,13 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
// first check the global keychain storage // first check the global keychain storage
NSString *username = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName] ?: @""; NSString *username = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName] ?: @"";
if (self.delegate && [self.delegate respondsToSelector:@selector(userNameForCrashManager:)]) { if ([self.delegate respondsToSelector:@selector(userNameForCrashManager:)]) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
username = [self.delegate userNameForCrashManager:self] ?: @""; username = [self.delegate userNameForCrashManager:self] ?: @"";
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
username = [[BITHockeyManager sharedHockeyManager].delegate username = [[BITHockeyManager sharedHockeyManager].delegate
userNameForHockeyManager:[BITHockeyManager sharedHockeyManager] userNameForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self] ?: @""; componentManager:self] ?: @"";
@ -652,14 +650,13 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
} }
#endif #endif
if (self.delegate && [self.delegate respondsToSelector:@selector(userEmailForCrashManager:)]) { if ([self.delegate respondsToSelector:@selector(userEmailForCrashManager:)]) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
useremail = [self.delegate userEmailForCrashManager:self] ?: @""; useremail = [self.delegate userEmailForCrashManager:self] ?: @"";
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userEmailForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userEmailForHockeyManager:componentManager:)]) {
useremail = [[BITHockeyManager sharedHockeyManager].delegate useremail = [[BITHockeyManager sharedHockeyManager].delegate
userEmailForHockeyManager:[BITHockeyManager sharedHockeyManager] userEmailForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self] ?: @""; componentManager:self] ?: @"";
@ -754,12 +751,12 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[self addStringValueToKeychain:[self userEmailForCrashReport] forKey:[NSString stringWithFormat:@"%@.%@", filename, kBITCrashMetaUserEmail]]; [self addStringValueToKeychain:[self userEmailForCrashReport] forKey:[NSString stringWithFormat:@"%@.%@", filename, kBITCrashMetaUserEmail]];
[self addStringValueToKeychain:[self userIDForCrashReport] forKey:[NSString stringWithFormat:@"%@.%@", filename, kBITCrashMetaUserID]]; [self addStringValueToKeychain:[self userIDForCrashReport] forKey:[NSString stringWithFormat:@"%@.%@", filename, kBITCrashMetaUserID]];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(applicationLogForCrashManager:)]) { if ([self.delegate respondsToSelector:@selector(applicationLogForCrashManager:)]) {
applicationLog = [self.delegate applicationLogForCrashManager:self] ?: @""; applicationLog = [self.delegate applicationLogForCrashManager:self] ?: @"";
} }
[metaDict setObject:applicationLog forKey:kBITCrashMetaApplicationLog]; [metaDict setObject:applicationLog forKey:kBITCrashMetaApplicationLog];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(attachmentForCrashManager:)]) { if ([self.delegate respondsToSelector:@selector(attachmentForCrashManager:)]) {
BITHockeyAttachment *attachment = [self.delegate attachmentForCrashManager:self]; BITHockeyAttachment *attachment = [self.delegate attachmentForCrashManager:self];
if (attachment && attachment.hockeyAttachmentData) { if (attachment && attachment.hockeyAttachmentData) {
@ -781,7 +778,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
- (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData { - (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData {
switch (userInput) { switch (userInput) {
case BITCrashManagerUserInputDontSend: case BITCrashManagerUserInputDontSend:
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) { if ([self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) {
[self.delegate crashManagerWillCancelSendingCrashReport:self]; [self.delegate crashManagerWillCancelSendingCrashReport:self];
} }
@ -802,7 +799,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
_crashManagerStatus = BITCrashManagerStatusAutoSend; _crashManagerStatus = BITCrashManagerStatusAutoSend;
[[NSUserDefaults standardUserDefaults] setInteger:_crashManagerStatus forKey:kBITCrashManagerStatus]; [[NSUserDefaults standardUserDefaults] setInteger:_crashManagerStatus forKey:kBITCrashManagerStatus];
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReportsAlways:)]) { if ([self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReportsAlways:)]) {
[self.delegate crashManagerWillSendCrashReportsAlways:self]; [self.delegate crashManagerWillSendCrashReportsAlways:self];
} }
@ -957,7 +954,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
return YES; return YES;
} else { } else {
if (_didCrashInLastSession) { if (_didCrashInLastSession) {
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) { if ([self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) {
[self.delegate crashManagerWillCancelSendingCrashReport:self]; [self.delegate crashManagerWillCancelSendingCrashReport:self];
} }
@ -1024,7 +1021,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[self sendNextCrashReport]; [self sendNextCrashReport];
} else if (_crashManagerStatus != BITCrashManagerStatusAutoSend && notApprovedReportFilename) { } else if (_crashManagerStatus != BITCrashManagerStatusAutoSend && notApprovedReportFilename) {
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillShowSubmitCrashReportAlert:)]) { if ([self.delegate respondsToSelector:@selector(crashManagerWillShowSubmitCrashReportAlert:)]) {
[self.delegate crashManagerWillShowSubmitCrashReportAlert:self]; [self.delegate crashManagerWillShowSubmitCrashReportAlert:self];
} }
@ -1172,8 +1169,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
if (!didAppSwitchToBackgroundSafely) { if (!didAppSwitchToBackgroundSafely) {
BOOL considerReport = YES; BOOL considerReport = YES;
if (self.delegate && if ([self.delegate respondsToSelector:@selector(considerAppNotTerminatedCleanlyReportForCrashManager:)]) {
[self.delegate respondsToSelector:@selector(considerAppNotTerminatedCleanlyReportForCrashManager:)]) {
considerReport = [self.delegate considerAppNotTerminatedCleanlyReportForCrashManager:self]; considerReport = [self.delegate considerAppNotTerminatedCleanlyReportForCrashManager:self];
} }
@ -1551,8 +1547,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
error:&theError]; error:&theError];
BITHockeyLog(@"INFO: Received API response: %@", response); BITHockeyLog(@"INFO: Received API response: %@", response);
if (self.delegate != nil && if ([self.delegate respondsToSelector:@selector(crashManagerDidFinishSendingCrashReport:)]) {
[self.delegate respondsToSelector:@selector(crashManagerDidFinishSendingCrashReport:)]) {
[self.delegate crashManagerDidFinishSendingCrashReport:self]; [self.delegate crashManagerDidFinishSendingCrashReport:self];
} }
@ -1578,8 +1573,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
} }
if (theError) { if (theError) {
if (self.delegate != nil && if ([self.delegate respondsToSelector:@selector(crashManager:didFailWithError:)]) {
[self.delegate respondsToSelector:@selector(crashManager:didFailWithError:)]) {
[self.delegate crashManager:self didFailWithError:theError]; [self.delegate crashManager:self didFailWithError:theError];
} }
@ -1642,7 +1636,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[self.hockeyAppClient enqeueHTTPOperation:operation]; [self.hockeyAppClient enqeueHTTPOperation:operation];
} }
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReport:)]) { if ([self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReport:)]) {
[self.delegate crashManagerWillSendCrashReport:self]; [self.delegate crashManagerWillSendCrashReport:self];
} }

View File

@ -467,9 +467,9 @@
} }
- (void)dismissWithResult:(BITFeedbackComposeResult) result { - (void)dismissWithResult:(BITFeedbackComposeResult) result {
if(self.delegate && [self.delegate respondsToSelector:@selector(feedbackComposeViewController:didFinishWithResult:)]) { if([self.delegate respondsToSelector:@selector(feedbackComposeViewController:didFinishWithResult:)]) {
[self.delegate feedbackComposeViewController:self didFinishWithResult:result]; [self.delegate feedbackComposeViewController:self didFinishWithResult:result];
} else if (self.delegate && [self.delegate respondsToSelector:@selector(feedbackComposeViewControllerDidFinish:)]) { } else if ([self.delegate respondsToSelector:@selector(feedbackComposeViewControllerDidFinish:)]) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
[self.delegate feedbackComposeViewControllerDidFinish:self]; [self.delegate feedbackComposeViewControllerDidFinish:self];

View File

@ -386,10 +386,9 @@
[self dismissViewControllerAnimated:YES completion:^(void){}]; [self dismissViewControllerAnimated:YES completion:^(void){}];
} }
if (self.manager.delegate && if ([self.manager.delegate respondsToSelector:@selector(feedbackComposeViewController:didFinishWithResult:)]) {
[self.manager.delegate respondsToSelector:@selector(feedbackComposeViewController:didFinishWithResult:)]) {
[self.manager.delegate feedbackComposeViewController:composeViewController didFinishWithResult:composeResult]; [self.manager.delegate feedbackComposeViewController:composeViewController didFinishWithResult:composeResult];
} else if (self.manager.delegate && [self.manager.delegate respondsToSelector:@selector(feedbackComposeViewControllerDidFinish:)]) { } else if ([self.manager.delegate respondsToSelector:@selector(feedbackComposeViewControllerDidFinish:)]) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
[self.manager.delegate feedbackComposeViewControllerDidFinish:composeViewController]; [self.manager.delegate feedbackComposeViewControllerDidFinish:composeViewController];

View File

@ -279,8 +279,7 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
- (BOOL)allowFetchingNewMessages { - (BOOL)allowFetchingNewMessages {
BOOL fetchNewMessages = YES; BOOL fetchNewMessages = YES;
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(allowAutomaticFetchingForNewFeedbackForManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(allowAutomaticFetchingForNewFeedbackForManager:)]) {
fetchNewMessages = [[BITHockeyManager sharedHockeyManager].delegate fetchNewMessages = [[BITHockeyManager sharedHockeyManager].delegate
allowAutomaticFetchingForNewFeedbackForManager:self]; allowAutomaticFetchingForNewFeedbackForManager:self];
} }
@ -310,8 +309,7 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
NSString *userID = [self stringValueFromKeychainForKey:kBITHockeyMetaUserID]; NSString *userID = [self stringValueFromKeychainForKey:kBITHockeyMetaUserID];
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userIDForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userIDForHockeyManager:componentManager:)]) {
userID = [[BITHockeyManager sharedHockeyManager].delegate userID = [[BITHockeyManager sharedHockeyManager].delegate
userIDForHockeyManager:[BITHockeyManager sharedHockeyManager] userIDForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self]; componentManager:self];
@ -330,8 +328,7 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
NSString *userName = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName]; NSString *userName = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName];
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
userName = [[BITHockeyManager sharedHockeyManager].delegate userName = [[BITHockeyManager sharedHockeyManager].delegate
userNameForHockeyManager:[BITHockeyManager sharedHockeyManager] userNameForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self]; componentManager:self];
@ -351,8 +348,7 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
NSString *userEmail = [self stringValueFromKeychainForKey:kBITHockeyMetaUserEmail]; NSString *userEmail = [self stringValueFromKeychainForKey:kBITHockeyMetaUserEmail];
if ([BITHockeyManager sharedHockeyManager].delegate && if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userEmailForHockeyManager:componentManager:)]) {
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userEmailForHockeyManager:componentManager:)]) {
userEmail = [[BITHockeyManager sharedHockeyManager].delegate userEmail = [[BITHockeyManager sharedHockeyManager].delegate
userEmailForHockeyManager:[BITHockeyManager sharedHockeyManager] userEmailForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self]; componentManager:self];

View File

@ -293,7 +293,7 @@
} }
if ([self isUpdateAvailable]) { if ([self isUpdateAvailable]) {
if (self.delegate && [self.delegate respondsToSelector:@selector(detectedUpdateFromStoreUpdateManager:newVersion:storeURL:)]) { if ([self.delegate respondsToSelector:@selector(detectedUpdateFromStoreUpdateManager:newVersion:storeURL:)]) {
[self.delegate detectedUpdateFromStoreUpdateManager:self newVersion:_newStoreVersion storeURL:[NSURL URLWithString:_appStoreURLString]]; [self.delegate detectedUpdateFromStoreUpdateManager:self newVersion:_newStoreVersion storeURL:[NSURL URLWithString:_appStoreURLString]];
} }

View File

@ -117,7 +117,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
// we only care about iOS 8 or later // we only care about iOS 8 or later
if (bit_isPreiOS8Environment()) return; if (bit_isPreiOS8Environment()) return;
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(updateManagerWillExitApp:)]) { if ([self.delegate respondsToSelector:@selector(updateManagerWillExitApp:)]) {
[self.delegate updateManagerWillExitApp:self]; [self.delegate updateManagerWillExitApp:self];
} }
@ -220,7 +220,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
BOOL shouldShowDefaultAlert = YES; BOOL shouldShowDefaultAlert = YES;
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(shouldDisplayExpiryAlertForUpdateManager:)]) { if ([self.delegate respondsToSelector:@selector(shouldDisplayExpiryAlertForUpdateManager:)]) {
shouldShowDefaultAlert = [self.delegate shouldDisplayExpiryAlertForUpdateManager:self]; shouldShowDefaultAlert = [self.delegate shouldDisplayExpiryAlertForUpdateManager:self];
} }
@ -230,7 +230,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
_blockingScreenMessage = [NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateExpired"), appName]; _blockingScreenMessage = [NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateExpired"), appName];
[self showBlockingScreen:_blockingScreenMessage image:@"authorize_denied.png"]; [self showBlockingScreen:_blockingScreenMessage image:@"authorize_denied.png"];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(didDisplayExpiryAlertForUpdateManager:)]) { if ([self.delegate respondsToSelector:@selector(didDisplayExpiryAlertForUpdateManager:)]) {
[self.delegate didDisplayExpiryAlertForUpdateManager:self]; [self.delegate didDisplayExpiryAlertForUpdateManager:self];
} }
@ -767,7 +767,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
NSString *iOSUpdateURL = [NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@", bit_URLEncodedString(hockeyAPIURL)]; NSString *iOSUpdateURL = [NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@", bit_URLEncodedString(hockeyAPIURL)];
// Notify delegate of update intent before placing the call // Notify delegate of update intent before placing the call
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(willStartDownloadAndUpdate:)]) { if ([self.delegate respondsToSelector:@selector(willStartDownloadAndUpdate:)]) {
[self.delegate willStartDownloadAndUpdate:self]; [self.delegate willStartDownloadAndUpdate:self];
} }
@ -790,7 +790,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
BITHockeyLog(@"INFO: Starting UpdateManager"); BITHockeyLog(@"INFO: Starting UpdateManager");
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(updateManagerShouldSendUsageData:)]) { if ([self.delegate respondsToSelector:@selector(updateManagerShouldSendUsageData:)]) {
_sendUsageData = [self.delegate updateManagerShouldSendUsageData:self]; _sendUsageData = [self.delegate updateManagerShouldSendUsageData:self];
} }