diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m index 54107d2b5..0b18fe51a 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m @@ -291,8 +291,8 @@ - (void)testDecodeQueryStringToDictionary { #pragma mark - Test Util methods - (NSString *)stringForDate:(NSDate *)date { - static NSDateFormatter *dateFormatter; - static dispatch_once_t onceToken; + static NSDateFormatter *dateFormatter = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ dateFormatter = [[NSDateFormatter alloc] init]; diff --git a/Sources/BranchSDK/BNCAppGroupsData.m b/Sources/BranchSDK/BNCAppGroupsData.m index 8ce782b95..cb4908f86 100644 --- a/Sources/BranchSDK/BNCAppGroupsData.m +++ b/Sources/BranchSDK/BNCAppGroupsData.m @@ -18,8 +18,8 @@ @interface BNCAppGroupsData() @implementation BNCAppGroupsData + (instancetype)shared { - static BNCAppGroupsData *appGroupsData; - static dispatch_once_t onceToken; + static BNCAppGroupsData *appGroupsData = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ appGroupsData = [BNCAppGroupsData new]; }); diff --git a/Sources/BranchSDK/BNCAppleReceipt.m b/Sources/BranchSDK/BNCAppleReceipt.m index ea54b4947..3536b7e89 100644 --- a/Sources/BranchSDK/BNCAppleReceipt.m +++ b/Sources/BranchSDK/BNCAppleReceipt.m @@ -23,8 +23,8 @@ @interface BNCAppleReceipt() @implementation BNCAppleReceipt + (BNCAppleReceipt *)sharedInstance { - static BNCAppleReceipt *singleton; - static dispatch_once_t onceToken; + static BNCAppleReceipt *singleton = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ singleton = [BNCAppleReceipt new]; }); diff --git a/Sources/BranchSDK/BNCCallbackMap.m b/Sources/BranchSDK/BNCCallbackMap.m index 8c1803824..ae5e4e829 100644 --- a/Sources/BranchSDK/BNCCallbackMap.m +++ b/Sources/BranchSDK/BNCCallbackMap.m @@ -15,8 +15,8 @@ @interface BNCCallbackMap() @implementation BNCCallbackMap + (instancetype)shared { - static BNCCallbackMap *map; - static dispatch_once_t onceToken; + static BNCCallbackMap *map = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ map = [BNCCallbackMap new]; }); diff --git a/Sources/BranchSDK/BNCDeviceInfo.m b/Sources/BranchSDK/BNCDeviceInfo.m index ef933b86d..dd6f1926d 100644 --- a/Sources/BranchSDK/BNCDeviceInfo.m +++ b/Sources/BranchSDK/BNCDeviceInfo.m @@ -34,7 +34,7 @@ @interface BNCDeviceInfo() @implementation BNCDeviceInfo + (BNCDeviceInfo *)getInstance { - static BNCDeviceInfo *bnc_deviceInfo = 0; + static BNCDeviceInfo *bnc_deviceInfo = nil; static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ bnc_deviceInfo = [BNCDeviceInfo new]; diff --git a/Sources/BranchSDK/BNCEncodingUtils.m b/Sources/BranchSDK/BNCEncodingUtils.m index 2ed69555c..c07f3dcbb 100644 --- a/Sources/BranchSDK/BNCEncodingUtils.m +++ b/Sources/BranchSDK/BNCEncodingUtils.m @@ -129,9 +129,8 @@ + (NSString *)sha256Encode:(NSString *)input { #pragma mark - Param Encoding methods + (NSString *)iso8601StringFromDate:(NSDate *)date { - static NSDateFormatter *dateFormatter; - static dispatch_once_t onceToken; - + static NSDateFormatter *dateFormatter = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; // POSIX to avoid weird issues diff --git a/Sources/BranchSDK/BNCEventUtils.m b/Sources/BranchSDK/BNCEventUtils.m index 911d60694..f65d90c22 100644 --- a/Sources/BranchSDK/BNCEventUtils.m +++ b/Sources/BranchSDK/BNCEventUtils.m @@ -15,8 +15,8 @@ @interface BNCEventUtils() @implementation BNCEventUtils + (instancetype)shared { - static BNCEventUtils *set; - static dispatch_once_t onceToken; + static BNCEventUtils *set = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ set = [BNCEventUtils new]; }); diff --git a/Sources/BranchSDK/BNCKeyChain.m b/Sources/BranchSDK/BNCKeyChain.m index 12dfaa640..a8e0a3e56 100644 --- a/Sources/BranchSDK/BNCKeyChain.m +++ b/Sources/BranchSDK/BNCKeyChain.m @@ -149,9 +149,9 @@ + (NSError*) removeValuesForService:(NSString *)service key:(NSString *)key { // The security access group string is prefixed with the Apple Developer Team ID + (NSString * _Nullable)securityAccessGroup { - @synchronized(self) { - static NSString *_securityAccessGroup = nil; - if (_securityAccessGroup) return _securityAccessGroup; + static NSString *_securityAccessGroup = nil; + static dispatch_once_t onceToken = 0; + dispatch_once(&onceToken, ^{ // The keychain cannot be empty prior to requesting the security access group string. Add a tmp variable. NSError *error = [self storeDate:[NSDate date] forService:@"BranchKeychainService" key:@"Temp" cloudAccessGroup:nil]; @@ -168,18 +168,23 @@ + (NSString * _Nullable)securityAccessGroup { }; CFDictionaryRef resultDictionary = NULL; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef*)&resultDictionary); - if (status == errSecItemNotFound) return nil; + + if (status == errSecItemNotFound) { + return; + } if (status != errSecSuccess) { [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Failed to retrieve security access group"] error:[self errorWithKey:nil OSStatus:status]]; - return nil; + return; } NSString *group = [(__bridge NSDictionary *)resultDictionary objectForKey:(__bridge NSString *)kSecAttrAccessGroup]; if (group.length > 0) { _securityAccessGroup = [group copy]; } CFRelease(resultDictionary); - return _securityAccessGroup; - } + }); + + return _securityAccessGroup; + } @end diff --git a/Sources/BranchSDK/BNCPartnerParameters.m b/Sources/BranchSDK/BNCPartnerParameters.m index c8642e488..e3048f8a0 100644 --- a/Sources/BranchSDK/BNCPartnerParameters.m +++ b/Sources/BranchSDK/BNCPartnerParameters.m @@ -16,8 +16,8 @@ @interface BNCPartnerParameters() @implementation BNCPartnerParameters + (instancetype)shared { - static BNCPartnerParameters *partnerParameters; - static dispatch_once_t onceToken; + static BNCPartnerParameters *partnerParameters = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ partnerParameters = [BNCPartnerParameters new]; }); diff --git a/Sources/BranchSDK/BNCPasteboard.m b/Sources/BranchSDK/BNCPasteboard.m index d1fe4765c..0ce70bb66 100644 --- a/Sources/BranchSDK/BNCPasteboard.m +++ b/Sources/BranchSDK/BNCPasteboard.m @@ -13,8 +13,8 @@ @implementation BNCPasteboard + (BNCPasteboard *)sharedInstance { - static BNCPasteboard *pasteboard; - static dispatch_once_t onceToken; + static BNCPasteboard *pasteboard = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ pasteboard = [BNCPasteboard new]; }); diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index 730fcbe1a..ff4eacafa 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -122,8 +122,8 @@ @implementation BNCPreferenceHelper adUserDataUsageConsent = _adUserDataUsageConsent; + (BNCPreferenceHelper *)sharedInstance { - static BNCPreferenceHelper *preferenceHelper; - static dispatch_once_t onceToken; + static BNCPreferenceHelper *preferenceHelper = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ preferenceHelper = [[BNCPreferenceHelper alloc] init]; diff --git a/Sources/BranchSDK/BNCQRCodeCache.m b/Sources/BranchSDK/BNCQRCodeCache.m index 2efa1996f..b77723e64 100644 --- a/Sources/BranchSDK/BNCQRCodeCache.m +++ b/Sources/BranchSDK/BNCQRCodeCache.m @@ -16,8 +16,8 @@ @implementation BNCQRCodeCache //Can only hold one QR code in cache. Just used to debounce. + (BNCQRCodeCache *) sharedInstance { - static BNCQRCodeCache *singleton; - static dispatch_once_t onceToken; + static BNCQRCodeCache *singleton = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ singleton = [BNCQRCodeCache new]; }); diff --git a/Sources/BranchSDK/BNCReachability.m b/Sources/BranchSDK/BNCReachability.m index d1516c785..ddc98e6e9 100644 --- a/Sources/BranchSDK/BNCReachability.m +++ b/Sources/BranchSDK/BNCReachability.m @@ -28,8 +28,8 @@ @interface BNCReachability() @implementation BNCReachability + (BNCReachability *)shared { - static BNCReachability *reachability; - static dispatch_once_t onceToken; + static BNCReachability *reachability = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ reachability = [BNCReachability new]; }); diff --git a/Sources/BranchSDK/BNCSKAdNetwork.m b/Sources/BranchSDK/BNCSKAdNetwork.m index e1de4b436..f5d05be60 100644 --- a/Sources/BranchSDK/BNCSKAdNetwork.m +++ b/Sources/BranchSDK/BNCSKAdNetwork.m @@ -27,8 +27,8 @@ @interface BNCSKAdNetwork() @implementation BNCSKAdNetwork + (BNCSKAdNetwork *)sharedInstance { - static BNCSKAdNetwork *singleton; - static dispatch_once_t onceToken; + static BNCSKAdNetwork *singleton = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ singleton = [[BNCSKAdNetwork alloc] init]; }); diff --git a/Sources/BranchSDK/BNCServerAPI.m b/Sources/BranchSDK/BNCServerAPI.m index 73f8cb253..15f40ff8e 100644 --- a/Sources/BranchSDK/BNCServerAPI.m +++ b/Sources/BranchSDK/BNCServerAPI.m @@ -14,8 +14,8 @@ @implementation BNCServerAPI + (BNCServerAPI *)sharedInstance { - static BNCServerAPI *serverAPI; - static dispatch_once_t onceToken; + static BNCServerAPI *serverAPI = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ serverAPI = [[BNCServerAPI alloc] init]; diff --git a/Sources/BranchSDK/BNCServerRequestQueue.m b/Sources/BranchSDK/BNCServerRequestQueue.m index 3beb7136e..28bdd988a 100755 --- a/Sources/BranchSDK/BNCServerRequestQueue.m +++ b/Sources/BranchSDK/BNCServerRequestQueue.m @@ -340,7 +340,7 @@ - (id)unarchiveObjectFromData:(NSData *)data { // only replay analytics requests, the others are time sensitive + (NSSet *)replayableRequestClasses { static NSSet *requestClasses = nil; - static dispatch_once_t onceToken; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^ { NSArray *tmp = @[ [BranchOpenRequest class], @@ -356,7 +356,7 @@ - (id)unarchiveObjectFromData:(NSData *)data { // encodable classes also includes NSArray and NSData + (NSSet *)encodableClasses { static NSSet *classes = nil; - static dispatch_once_t onceToken; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^ { NSMutableArray *tmp = [NSMutableArray new]; [tmp addObject:[NSArray class]]; // root object @@ -373,7 +373,7 @@ - (id)unarchiveObjectFromData:(NSData *)data { + (NSURL * _Nonnull) URLForQueueFile { static NSURL *URL = nil; - static dispatch_once_t onceToken; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^ { URL = BNCURLForBranchDirectory(); URL = [URL URLByAppendingPathComponent:BRANCH_QUEUE_FILE isDirectory:NO]; @@ -383,7 +383,7 @@ + (NSURL * _Nonnull) URLForQueueFile { + (instancetype)getInstance { static BNCServerRequestQueue *sharedQueue = nil; - static dispatch_once_t onceToken; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^ { sharedQueue = [[BNCServerRequestQueue alloc] init]; [sharedQueue retrieve]; diff --git a/Sources/BranchSDK/BNCUserAgentCollector.m b/Sources/BranchSDK/BNCUserAgentCollector.m index 029173f4c..d6a77f064 100644 --- a/Sources/BranchSDK/BNCUserAgentCollector.m +++ b/Sources/BranchSDK/BNCUserAgentCollector.m @@ -26,8 +26,8 @@ @interface BNCUserAgentCollector() @implementation BNCUserAgentCollector + (BNCUserAgentCollector *)instance { - static BNCUserAgentCollector *collector; - static dispatch_once_t onceToken; + static BNCUserAgentCollector *collector = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ collector = [BNCUserAgentCollector new]; }); diff --git a/Sources/BranchSDK/BranchContentDiscoverer.m b/Sources/BranchSDK/BranchContentDiscoverer.m index c9fa3394e..f186ebbd0 100644 --- a/Sources/BranchSDK/BranchContentDiscoverer.m +++ b/Sources/BranchSDK/BranchContentDiscoverer.m @@ -27,12 +27,11 @@ @implementation BranchContentDiscoverer + (BranchContentDiscoverer *)getInstance { static BranchContentDiscoverer *sharedInstance = nil; - @synchronized (self) { - if (!sharedInstance) { - sharedInstance = [[BranchContentDiscoverer alloc] init]; - } + static dispatch_once_t onceToken = 0; + dispatch_once(&onceToken, ^{ + sharedInstance = [BranchContentDiscoverer new]; + }); return sharedInstance; - } } - (void) dealloc { diff --git a/Sources/BranchSDK/BranchContentDiscoveryManifest.m b/Sources/BranchSDK/BranchContentDiscoveryManifest.m index e10585954..fc5e6163d 100644 --- a/Sources/BranchSDK/BranchContentDiscoveryManifest.m +++ b/Sources/BranchSDK/BranchContentDiscoveryManifest.m @@ -34,13 +34,12 @@ - (instancetype)init { } + (BranchContentDiscoveryManifest *)getInstance { - @synchronized (self) { - static BranchContentDiscoveryManifest *contentDiscoveryManifest = nil; - if (!contentDiscoveryManifest) { - contentDiscoveryManifest = [[BranchContentDiscoveryManifest alloc] init]; - } - return contentDiscoveryManifest; - } + static BranchContentDiscoveryManifest *sharedInstance = nil; + static dispatch_once_t onceToken = 0; + dispatch_once(&onceToken, ^{ + sharedInstance = [BranchContentDiscoveryManifest new]; + }); + return sharedInstance; } - (void)onBranchInitialised:(NSDictionary *)branchInitDict withUrl:(NSString *)referringURL { diff --git a/Sources/BranchSDK/BranchJsonConfig.m b/Sources/BranchSDK/BranchJsonConfig.m index 430c6b859..a27850daa 100644 --- a/Sources/BranchSDK/BranchJsonConfig.m +++ b/Sources/BranchSDK/BranchJsonConfig.m @@ -28,16 +28,13 @@ @interface BranchJsonConfig() @implementation BranchJsonConfig -+ (BranchJsonConfig * _Nonnull)instance -{ - @synchronized(self) { - static BranchJsonConfig *_instance; - static dispatch_once_t once = 0; - dispatch_once(&once, ^{ - _instance = [[BranchJsonConfig alloc] init]; - }); - return _instance; - } ++ (BranchJsonConfig * _Nonnull)instance { + static BranchJsonConfig *instance = nil; + static dispatch_once_t once = 0; + dispatch_once(&once, ^{ + instance = [BranchJsonConfig new]; + }); + return instance; } - (instancetype)init diff --git a/Sources/BranchSDK/BranchLogger.m b/Sources/BranchSDK/BranchLogger.m index 3f5038b57..d64a65568 100644 --- a/Sources/BranchSDK/BranchLogger.m +++ b/Sources/BranchSDK/BranchLogger.m @@ -31,7 +31,7 @@ - (instancetype)init { + (instancetype)shared { static BranchLogger *sharedInstance = nil; - static dispatch_once_t onceToken; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ sharedInstance = [[BranchLogger alloc] init]; sharedInstance.loggingEnabled = NO; diff --git a/Sources/BranchSDK/BranchPluginSupport.m b/Sources/BranchSDK/BranchPluginSupport.m index c975d930b..7b0af19d3 100644 --- a/Sources/BranchSDK/BranchPluginSupport.m +++ b/Sources/BranchSDK/BranchPluginSupport.m @@ -16,8 +16,8 @@ @implementation BranchPluginSupport + (BranchPluginSupport *)instance { - static BranchPluginSupport *pluginSupport; - static dispatch_once_t onceToken; + static BranchPluginSupport *pluginSupport = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ pluginSupport = [BranchPluginSupport new]; }); diff --git a/Sources/BranchSDK/BranchScene.m b/Sources/BranchSDK/BranchScene.m index c4f3a2f53..cb176994e 100644 --- a/Sources/BranchSDK/BranchScene.m +++ b/Sources/BranchSDK/BranchScene.m @@ -13,8 +13,8 @@ @implementation BranchScene + (BranchScene *)shared NS_EXTENSION_UNAVAILABLE("BranchScene does not support Extensions") { - static BranchScene *bscene; - static dispatch_once_t onceToken; + static BranchScene *bscene = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ bscene = [BranchScene new]; }); diff --git a/Sources/BranchSDK/NSError+Branch.m b/Sources/BranchSDK/NSError+Branch.m index 1ffe8bd9d..5e06a6987 100644 --- a/Sources/BranchSDK/NSError+Branch.m +++ b/Sources/BranchSDK/NSError+Branch.m @@ -22,8 +22,8 @@ + (NSString *)bncErrorDomain { // Legacy error messages + (NSString *)messageForCode:(BNCErrorCode)code { - static NSMutableDictionary *messages; - static dispatch_once_t onceToken; + static NSMutableDictionary *messages = nil; + static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ messages = [NSMutableDictionary new]; [messages setObject:@"The Branch user session has not been initialized." forKey:@(BNCInitError)];