From a4c8d8aebaf86ac7d8e78f19ba0219f088cf019c Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Fri, 4 Dec 2020 11:29:10 +0000 Subject: [PATCH] Remove BSG***InsertIfNotNil --- Bugsnag.xcodeproj/project.pbxproj | 11 +---- Bugsnag/Helpers/BugsnagCollections.h | 17 -------- Bugsnag/Helpers/BugsnagCollections.m | 13 ------ .../Recording/BSG_KSCrashReportStore.m | 10 ++--- Bugsnag/Payload/BugsnagApp.m | 17 ++++---- Bugsnag/Payload/BugsnagAppWithState.m | 6 +-- Bugsnag/Payload/BugsnagDevice.m | 20 +++++----- Bugsnag/Payload/BugsnagDeviceWithState.m | 16 +++----- Bugsnag/Payload/BugsnagError.m | 6 +-- Bugsnag/Payload/BugsnagEvent.m | 6 +-- Bugsnag/Payload/BugsnagSession.m | 10 ++--- .../Payload/BugsnagSessionTrackingPayload.m | 2 +- Bugsnag/Payload/BugsnagStackframe.m | 6 +-- Bugsnag/Payload/BugsnagThread.m | 6 +-- Bugsnag/Payload/BugsnagUser.m | 6 +-- ...snagCollectionsBSGDictInsertIfNotNilTest.m | 40 ------------------- 16 files changed, 53 insertions(+), 139 deletions(-) delete mode 100644 Tests/BugsnagCollectionsBSGDictInsertIfNotNilTest.m diff --git a/Bugsnag.xcodeproj/project.pbxproj b/Bugsnag.xcodeproj/project.pbxproj index aead8db71..77bd97703 100644 --- a/Bugsnag.xcodeproj/project.pbxproj +++ b/Bugsnag.xcodeproj/project.pbxproj @@ -37,9 +37,6 @@ 008966F72486D43700DC48C2 /* RegisterErrorDataTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966A92486D43400DC48C2 /* RegisterErrorDataTest.m */; }; 008966F82486D43700DC48C2 /* RegisterErrorDataTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966A92486D43400DC48C2 /* RegisterErrorDataTest.m */; }; 008966F92486D43700DC48C2 /* RegisterErrorDataTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966A92486D43400DC48C2 /* RegisterErrorDataTest.m */; }; - 008966FA2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AA2486D43400DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m */; }; - 008966FB2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AA2486D43400DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m */; }; - 008966FC2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AA2486D43400DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m */; }; 008966FD2486D43700DC48C2 /* BugsnagOnBreadcrumbTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AB2486D43500DC48C2 /* BugsnagOnBreadcrumbTest.m */; }; 008966FE2486D43700DC48C2 /* BugsnagOnBreadcrumbTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AB2486D43500DC48C2 /* BugsnagOnBreadcrumbTest.m */; }; 008966FF2486D43700DC48C2 /* BugsnagOnBreadcrumbTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008966AB2486D43500DC48C2 /* BugsnagOnBreadcrumbTest.m */; }; @@ -655,9 +652,8 @@ 00AD1F302486A17900A27979 /* BugsnagSessionTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 00AD1F012486A17900A27979 /* BugsnagSessionTracker.m */; }; 00AD1F312486A17900A27979 /* BugsnagSessionTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 00AD1F012486A17900A27979 /* BugsnagSessionTracker.m */; }; 00E636C224878D84006CBF1A /* BSG_RFC3339DateTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 008969142486DAD000DC48C2 /* BSG_RFC3339DateTool.m */; }; - 0140D29A25767C9A00FD0306 /* BugsnagApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */; }; 012482A325627B51003F7243 /* UIKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 012482A225627B51003F7243 /* UIKitTests.m */; }; - 014475FD2566844F0018AB94 /* BugsnagApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */; }; + 0140D29A25767C9A00FD0306 /* BugsnagApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */; }; 01447605256684500018AB94 /* BugsnagApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */; }; 0187D464255BD7B800C503D9 /* BugsnagApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */; }; 01B14C56251CE55F00118748 /* report-react-native-promise-rejection.json in Resources */ = {isa = PBXBuildFile; fileRef = 01B14C55251CE55F00118748 /* report-react-native-promise-rejection.json */; }; @@ -1054,7 +1050,6 @@ 008966A72486D43400DC48C2 /* BugsnagThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagThreadTest.m; sourceTree = ""; }; 008966A82486D43400DC48C2 /* BugsnagTestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BugsnagTestConstants.h; sourceTree = ""; }; 008966A92486D43400DC48C2 /* RegisterErrorDataTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegisterErrorDataTest.m; sourceTree = ""; }; - 008966AA2486D43400DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagCollectionsBSGDictInsertIfNotNilTest.m; sourceTree = ""; }; 008966AB2486D43500DC48C2 /* BugsnagOnBreadcrumbTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagOnBreadcrumbTest.m; sourceTree = ""; }; 008966AC2486D43500DC48C2 /* BugsnagEventPersistLoadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagEventPersistLoadTest.m; sourceTree = ""; }; 008966AD2486D43500DC48C2 /* BugsnagThreadSerializationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagThreadSerializationTest.m; sourceTree = ""; }; @@ -1659,7 +1654,6 @@ 008966CA2486D43600DC48C2 /* BugsnagClientMirrorTest.m */, 008966A52486D43400DC48C2 /* BugsnagClientPayloadInfoTest.m */, 008966BE2486D43500DC48C2 /* BugsnagClientTests.m */, - 008966AA2486D43400DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m */, 008966B42486D43500DC48C2 /* BugsnagCollectionsBSGDictMergeTest.m */, 008966CE2486D43600DC48C2 /* BugsnagCollectionsBSGDictSetSafeObjectTest.m */, 00896A432486DBF000DC48C2 /* BugsnagConfigurationTests.m */, @@ -2584,7 +2578,6 @@ 0089679F2486D43700DC48C2 /* KSCrashSentry_Tests.m in Sources */, 008967872486D43700DC48C2 /* KSCrashSentry_NSException_Tests.m in Sources */, 0089679C2486D43700DC48C2 /* KSFileUtils_Tests.m in Sources */, - 008966FA2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */, 008966EE2486D43700DC48C2 /* BugsnagClientPayloadInfoTest.m in Sources */, 008967782486D43700DC48C2 /* KSMachHeader_Tests.m in Sources */, 0089673F2486D43700DC48C2 /* BugsnagAppTest.m in Sources */, @@ -2712,7 +2705,6 @@ 008967882486D43700DC48C2 /* KSCrashSentry_NSException_Tests.m in Sources */, 0140D29A25767C9A00FD0306 /* BugsnagApiClientTest.m in Sources */, E701FAA02490EF4A008D842F /* BugsnagApiValidationTest.m in Sources */, - 008966FB2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */, 0089677F2486D43700DC48C2 /* KSLogger_Tests.m in Sources */, 008967342486D43700DC48C2 /* BugsnagClientTests.m in Sources */, 008967222486D43700DC48C2 /* BugsnagErrorReportSinkTests.m in Sources */, @@ -2872,7 +2864,6 @@ buildActionMask = 2147483647; files = ( 008967892486D43700DC48C2 /* KSCrashSentry_NSException_Tests.m in Sources */, - 008966FC2486D43700DC48C2 /* BugsnagCollectionsBSGDictInsertIfNotNilTest.m in Sources */, 008967802486D43700DC48C2 /* KSLogger_Tests.m in Sources */, 008967352486D43700DC48C2 /* BugsnagClientTests.m in Sources */, 008967232486D43700DC48C2 /* BugsnagErrorReportSinkTests.m in Sources */, diff --git a/Bugsnag/Helpers/BugsnagCollections.h b/Bugsnag/Helpers/BugsnagCollections.h index 205cd058b..f8e309c09 100644 --- a/Bugsnag/Helpers/BugsnagCollections.h +++ b/Bugsnag/Helpers/BugsnagCollections.h @@ -37,23 +37,6 @@ void BSGDictSetSafeObject(NSMutableDictionary *dict, id object, id ke */ void BSGArrayAddSafeObject(NSMutableArray *array, id object); -/** - * Insert an object into a collection only if not nil - * - * @param dict a mutable dictionary - * @param object an object or nil - * @param key the key of the object - */ -void BSGDictInsertIfNotNil(NSMutableDictionary *dict, id object, id key); - -/** - * Insert an object into a collection only if not nil - * - * @param array a mutable array - * @param object an object or nil - */ -void BSGArrayInsertIfNotNil(NSMutableArray *array, id object); - /** * Merge values from source dictionary with destination * diff --git a/Bugsnag/Helpers/BugsnagCollections.m b/Bugsnag/Helpers/BugsnagCollections.m index 26aa75f0f..74ec7633c 100644 --- a/Bugsnag/Helpers/BugsnagCollections.m +++ b/Bugsnag/Helpers/BugsnagCollections.m @@ -30,19 +30,6 @@ void BSGArrayAddSafeObject(NSMutableArray *array, id object) { [array addObject:object ?: [NSNull null]]; } -void BSGDictInsertIfNotNil(NSMutableDictionary *dict, id object, - id key) { - if (object && key) { - dict[key] = object; - } -} - -void BSGArrayInsertIfNotNil(NSMutableArray *array, id object) { - if (object) { - [array addObject:object]; - } -} - NSDictionary *BSGDictMerge(NSDictionary *source, NSDictionary *destination) { if ([destination count] == 0) { return source; diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReportStore.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReportStore.m index 909331620..f2c7a0df3 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReportStore.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReportStore.m @@ -87,7 +87,7 @@ - (NSDictionary *)fileWithId:(NSString *)fileId { NSMutableDictionary *fileContents = [NSMutableDictionary new]; NSMutableDictionary *recrashReport = [self readFile:[self pathToRecrashReportWithID:fileId] error:&error]; - BSGDictInsertIfNotNil(fileContents, recrashReport, @BSG_KSCrashField_RecrashReport); + fileContents[@BSG_KSCrashField_RecrashReport] = recrashReport; return fileContents; } } @@ -103,7 +103,7 @@ - (NSMutableDictionary *)fixupCrashReport:(NSDictionary *)report { NSMutableDictionary *mutableReport = [report mutableCopy]; NSMutableDictionary *mutableInfo = [report[@BSG_KSCrashField_Report] mutableCopy]; - BSGDictInsertIfNotNil(mutableReport, mutableInfo, @BSG_KSCrashField_Report); + mutableReport[@BSG_KSCrashField_Report] = mutableInfo; // Timestamp gets stored as a unix timestamp. Convert it to rfc3339. [self convertTimestamp:@BSG_KSCrashField_Timestamp inReport:mutableInfo]; @@ -118,9 +118,9 @@ - (NSMutableDictionary *)fixupCrashReport:(NSDictionary *)report { NSMutableDictionary *crashReport = [report[@BSG_KSCrashField_Crash] mutableCopy]; - BSGDictInsertIfNotNil(mutableReport, crashReport, @BSG_KSCrashField_Crash); + mutableReport[@BSG_KSCrashField_Crash] = crashReport; BSG_KSCrashDoctor *doctor = [BSG_KSCrashDoctor doctor]; - BSGDictInsertIfNotNil(crashReport, [doctor diagnoseCrash:report], @BSG_KSCrashField_Diagnosis); + crashReport[@BSG_KSCrashField_Diagnosis] = [doctor diagnoseCrash:report]; return mutableReport; } @@ -144,7 +144,7 @@ - (void)mergeDictWithKey:(NSString *)srcKey return; } - BSGDictInsertIfNotNil(report, BSGDictMerge(srcDict, dstDict), dstKey); + report[dstKey] = BSGDictMerge(srcDict, dstDict); [report removeObjectForKey:srcKey]; } diff --git a/Bugsnag/Payload/BugsnagApp.m b/Bugsnag/Payload/BugsnagApp.m index ef6711397..9be0fc29d 100644 --- a/Bugsnag/Payload/BugsnagApp.m +++ b/Bugsnag/Payload/BugsnagApp.m @@ -68,16 +68,13 @@ + (void)populateFields:(BugsnagApp *)app - (NSDictionary *)toDict { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.bundleVersion, @"bundleVersion"); - BSGDictInsertIfNotNil(dict, self.codeBundleId, @"codeBundleId"); - BSGDictInsertIfNotNil(dict, self.id, @"id"); - BSGDictInsertIfNotNil(dict, self.releaseStage, @"releaseStage"); - BSGDictInsertIfNotNil(dict, self.type, @"type"); - BSGDictInsertIfNotNil(dict, self.version, @"version"); - - if (self.dsymUuid != nil) { - BSGDictInsertIfNotNil(dict, @[self.dsymUuid], @"dsymUUIDs"); - } + dict[@"bundleVersion"] = self.bundleVersion; + dict[@"codeBundleId"] = self.codeBundleId; + dict[@"dsymUUIDs"] = self.dsymUuid ? @[self.dsymUuid] : nil; + dict[@"id"] = self.id; + dict[@"releaseStage"] = self.releaseStage; + dict[@"type"] = self.type; + dict[@"version"] = self.version; return dict; } diff --git a/Bugsnag/Payload/BugsnagAppWithState.m b/Bugsnag/Payload/BugsnagAppWithState.m index 21a52d747..581af2334 100644 --- a/Bugsnag/Payload/BugsnagAppWithState.m +++ b/Bugsnag/Payload/BugsnagAppWithState.m @@ -91,9 +91,9 @@ + (BugsnagAppWithState *)appWithDictionary:(NSDictionary *)event - (NSDictionary *)toDict { NSMutableDictionary *dict = (NSMutableDictionary *) [super toDict]; - BSGDictInsertIfNotNil(dict, self.duration, @"duration"); - BSGDictInsertIfNotNil(dict, self.durationInForeground, @"durationInForeground"); - BSGDictInsertIfNotNil(dict, @(self.inForeground), @"inForeground"); + dict[@"duration"] = self.duration; + dict[@"durationInForeground"] = self.durationInForeground; + dict[@"inForeground"] = @(self.inForeground); return dict; } diff --git a/Bugsnag/Payload/BugsnagDevice.m b/Bugsnag/Payload/BugsnagDevice.m index fdfeb6e52..8a99d1c73 100644 --- a/Bugsnag/Payload/BugsnagDevice.m +++ b/Bugsnag/Payload/BugsnagDevice.m @@ -56,16 +56,16 @@ + (void)populateFields:(BugsnagDevice *)device - (NSDictionary *)toDictionary { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, @(self.jailbroken), @"jailbroken"); - BSGDictInsertIfNotNil(dict, self.id, @"id"); - BSGDictInsertIfNotNil(dict, self.locale, @"locale"); - BSGDictInsertIfNotNil(dict, self.manufacturer, @"manufacturer"); - BSGDictInsertIfNotNil(dict, self.model, @"model"); - BSGDictInsertIfNotNil(dict, self.modelNumber, @"modelNumber"); - BSGDictInsertIfNotNil(dict, self.osName, @"osName"); - BSGDictInsertIfNotNil(dict, self.osVersion, @"osVersion"); - BSGDictInsertIfNotNil(dict, self.runtimeVersions, @"runtimeVersions"); - BSGDictInsertIfNotNil(dict, self.totalMemory, @"totalMemory"); + dict[@"jailbroken"] = @(self.jailbroken); + dict[@"id"] = self.id; + dict[@"locale"] = self.locale; + dict[@"manufacturer"] = self.manufacturer; + dict[@"model"] = self.model; + dict[@"modelNumber"] = self.modelNumber; + dict[@"osName"] = self.osName; + dict[@"osVersion"] = self.osVersion; + dict[@"runtimeVersions"] = self.runtimeVersions; + dict[@"totalMemory"] = self.totalMemory; return dict; } diff --git a/Bugsnag/Payload/BugsnagDeviceWithState.m b/Bugsnag/Payload/BugsnagDeviceWithState.m index 226a6e641..2fcea5ba0 100644 --- a/Bugsnag/Payload/BugsnagDeviceWithState.m +++ b/Bugsnag/Payload/BugsnagDeviceWithState.m @@ -19,7 +19,7 @@ NSMutableDictionary *device = [NSMutableDictionary new]; NSDictionary *state = [event valueForKeyPath:@"user.state.deviceState"]; [device addEntriesFromDictionary:state]; - BSGDictInsertIfNotNil(device, [event valueForKeyPath:@"system.time_zone"], @"timezone"); + device[@"timezone"] = [event valueForKeyPath:@"system.time_zone"]; #if BSG_PLATFORM_SIMULATOR BSGDictSetSafeObject(device, @YES, @"simulator"); @@ -128,15 +128,11 @@ + (BugsnagDeviceWithState *)deviceWithDictionary:(NSDictionary *)event { } - (NSDictionary *)toDictionary { - NSMutableDictionary *dict = (NSMutableDictionary *) - [super toDictionary]; - BSGDictInsertIfNotNil(dict, self.freeDisk, @"freeDisk"); - BSGDictInsertIfNotNil(dict, self.freeMemory, @"freeMemory"); - BSGDictInsertIfNotNil(dict, self.orientation, @"orientation"); - - if (self.time != nil) { - BSGDictInsertIfNotNil(dict, [BSG_RFC3339DateTool stringFromDate:self.time], @"time"); - } + NSMutableDictionary *dict = [[super toDictionary] mutableCopy]; + dict[@"freeDisk"] = self.freeDisk; + dict[@"freeMemory"] = self.freeMemory; + dict[@"orientation"] = self.orientation; + dict[@"time"] = self.time ? [BSG_RFC3339DateTool stringFromDate:self.time] : nil; return dict; } diff --git a/Bugsnag/Payload/BugsnagError.m b/Bugsnag/Payload/BugsnagError.m index 9a8fc7ddd..a98767137 100644 --- a/Bugsnag/Payload/BugsnagError.m +++ b/Bugsnag/Payload/BugsnagError.m @@ -149,9 +149,9 @@ - (NSDictionary *)findErrorReportingThread:(NSDictionary *)event { - (NSDictionary *)toDictionary { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.errorClass, BSGKeyErrorClass); - BSGDictInsertIfNotNil(dict, self.errorMessage, BSGKeyMessage); - BSGDictInsertIfNotNil(dict, BSGSerializeErrorType(self.type), BSGKeyType); + dict[BSGKeyErrorClass] = self.errorClass; + dict[BSGKeyMessage] = self.errorMessage; + dict[BSGKeyType] = BSGSerializeErrorType(self.type); NSMutableArray *frames = [NSMutableArray new]; for (BugsnagStackframe *frame in self.stacktrace) { diff --git a/Bugsnag/Payload/BugsnagEvent.m b/Bugsnag/Payload/BugsnagEvent.m index f23c0a848..fb70ad53e 100644 --- a/Bugsnag/Payload/BugsnagEvent.m +++ b/Bugsnag/Payload/BugsnagEvent.m @@ -691,7 +691,7 @@ - (NSDictionary *)toJson { BSGDictSetSafeObject(event, [self.app toDict], BSGKeyApp); BSGDictSetSafeObject(event, [self context], BSGKeyContext); - BSGDictInsertIfNotNil(event, self.groupingHash, BSGKeyGroupingHash); + event[BSGKeyGroupingHash] = self.groupingHash; BSGDictSetSafeObject(event, @(self.handledState.unhandled), BSGKeyUnhandled); @@ -713,10 +713,10 @@ - (NSDictionary *)toJson { // Inserted into `context` property [metadata removeObjectForKey:BSGKeyContext]; // Build metadata - BSGDictInsertIfNotNil(metadata, self.error, BSGKeyError); + metadata[BSGKeyError] = self.error; // add user - BSGDictInsertIfNotNil(event, [self.user toJson], BSGKeyUser); + event[BSGKeyUser] = [self.user toJson]; if (self.session) { BSGDictSetSafeObject(event, [self generateSessionDict], BSGKeySession); diff --git a/Bugsnag/Payload/BugsnagSession.m b/Bugsnag/Payload/BugsnagSession.m index d2aa50984..681704194 100644 --- a/Bugsnag/Payload/BugsnagSession.m +++ b/Bugsnag/Payload/BugsnagSession.m @@ -128,15 +128,15 @@ - (_Nonnull instancetype)initWithId:(NSString *_Nonnull)sessionId - (NSDictionary *)toJson { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.id, kBugsnagSessionId); - BSGDictInsertIfNotNil(dict, [BSG_RFC3339DateTool stringFromDate:self.startedAt], kBugsnagStartedAt); + dict[kBugsnagSessionId] = self.id; + dict[kBugsnagStartedAt] = [BSG_RFC3339DateTool stringFromDate:self.startedAt]; if (self.user) { - BSGDictInsertIfNotNil(dict, [self.user toJson], kBugsnagUser); + dict[kBugsnagUser] = [self.user toJson]; } - BSGDictInsertIfNotNil(dict, [self.app toDict], BSGKeyApp); - BSGDictInsertIfNotNil(dict, [self.device toDictionary], BSGKeyDevice); + dict[BSGKeyApp] = [self.app toDict]; + dict[BSGKeyDevice] = [self.device toDictionary]; return [NSDictionary dictionaryWithDictionary:dict]; } diff --git a/Bugsnag/Payload/BugsnagSessionTrackingPayload.m b/Bugsnag/Payload/BugsnagSessionTrackingPayload.m index adb0cd438..b1cf571f0 100644 --- a/Bugsnag/Payload/BugsnagSessionTrackingPayload.m +++ b/Bugsnag/Payload/BugsnagSessionTrackingPayload.m @@ -69,7 +69,7 @@ - (NSMutableDictionary *)toJson for (BugsnagSession *session in self.sessions) { [sessionData addObject:[session toDictionary]]; } - BSGDictInsertIfNotNil(dict, sessionData, @"sessions"); + dict[@"sessions"] = sessionData; BSGDictSetSafeObject(dict, [[Bugsnag client].notifier toDict], BSGKeyNotifier); // app/device data collection relies on KSCrash reports, diff --git a/Bugsnag/Payload/BugsnagStackframe.m b/Bugsnag/Payload/BugsnagStackframe.m index a248b01a8..416c8c771 100644 --- a/Bugsnag/Payload/BugsnagStackframe.m +++ b/Bugsnag/Payload/BugsnagStackframe.m @@ -160,9 +160,9 @@ - (NSString *)description { - (NSDictionary *)toDictionary { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.machoFile, BSGKeyMachoFile); - BSGDictInsertIfNotNil(dict, self.method, BSGKeyMethod); - BSGDictInsertIfNotNil(dict, self.machoUuid, BSGKeyMachoUUID); + dict[BSGKeyMachoFile] = self.machoFile; + dict[BSGKeyMethod] = self.method; + dict[BSGKeyMachoUUID] = self.machoUuid; if (self.frameAddress != nil) { NSString *frameAddr = [NSString stringWithFormat:BSGKeyFrameAddrFormat, [self.frameAddress unsignedLongValue]]; diff --git a/Bugsnag/Payload/BugsnagThread.m b/Bugsnag/Payload/BugsnagThread.m index a9bf3da9b..2d3999511 100644 --- a/Bugsnag/Payload/BugsnagThread.m +++ b/Bugsnag/Payload/BugsnagThread.m @@ -78,8 +78,8 @@ - (instancetype)initWithThread:(NSDictionary *)thread binaryImages:(NSArray *)bi - (NSDictionary *)toDictionary { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.id, @"id"); - BSGDictInsertIfNotNil(dict, self.name, @"name"); + dict[@"id"] = self.id; + dict[@"name"] = self.name; BSGDictSetSafeObject(dict, @(self.errorReportingThread), @"errorReportingThread"); BSGDictSetSafeObject(dict, BSGSerializeThreadType(self.type), @"type"); BSGDictSetSafeObject(dict, @(self.errorReportingThread), @"errorReportingThread"); @@ -155,7 +155,7 @@ + (NSDictionary *)enhanceThreadInfo:(NSDictionary *)thread if (seen == 2 && !stackOverflow && [@[BSGKeySignal, BSGKeyMach] containsObject:errorType]) { BSGDictSetSafeObject(mutableFrame, @YES, BSGKeyIsLR); } - BSGArrayInsertIfNotNil(stacktrace, mutableFrame); + [stacktrace addObject:mutableFrame]; } } NSMutableDictionary *copy = [NSMutableDictionary dictionaryWithDictionary:thread]; diff --git a/Bugsnag/Payload/BugsnagUser.m b/Bugsnag/Payload/BugsnagUser.m index 590858210..07bd5bb27 100644 --- a/Bugsnag/Payload/BugsnagUser.m +++ b/Bugsnag/Payload/BugsnagUser.m @@ -36,9 +36,9 @@ + (instancetype)userWithUserId:(NSString *)userId name:(NSString *)name emailAdd - (NSDictionary *)toJson { NSMutableDictionary *dict = [NSMutableDictionary new]; - BSGDictInsertIfNotNil(dict, self.id, @"id"); - BSGDictInsertIfNotNil(dict, self.email, @"email"); - BSGDictInsertIfNotNil(dict, self.name, @"name"); + dict[@"id"] = self.id; + dict[@"email"] = self.email; + dict[@"name"] = self.name; return [NSDictionary dictionaryWithDictionary:dict]; } diff --git a/Tests/BugsnagCollectionsBSGDictInsertIfNotNilTest.m b/Tests/BugsnagCollectionsBSGDictInsertIfNotNilTest.m deleted file mode 100644 index 5285313f7..000000000 --- a/Tests/BugsnagCollectionsBSGDictInsertIfNotNilTest.m +++ /dev/null @@ -1,40 +0,0 @@ -// -// BugsnagCollectionsBSGDictInsertIfNotNilTest.m -// Tests -// -// Created by Paul Zabelin on 7/2/19. -// Copyright © 2019 Bugsnag. All rights reserved. -// - -@import XCTest; -#import "BugsnagCollections.h" - -@interface BugsnagCollectionsBSGDictInsertIfNotNilTest : XCTestCase -@property (nonatomic, strong) NSMutableDictionary* dict; -@property (nonatomic, strong) NSString *key; -@end - -@implementation BugsnagCollectionsBSGDictInsertIfNotNilTest - -- (void)setUp { - self.key = @"some key value"; - self.dict = [NSMutableDictionary dictionary]; -} - -- (void)tearDown { - self.dict = nil; - self.key = nil; -} - -- (void)testBSGDictInsertIfNotNil_NotNil { - id object = @"blah"; - BSGDictInsertIfNotNil(self.dict, object, self.key); - XCTAssertEqual(self.dict[self.key], object, @"should be inserted"); -} - -- (void)testBSGDictInsertIfNotNil_Nil { - BSGDictInsertIfNotNil(self.dict, nil, self.key); - XCTAssertNil(self.dict[self.key], @"should not be inserted"); -} - -@end