From 293c3bf8640adb90b873d23d40568e93541a002f Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Fri, 1 Dec 2023 17:41:44 -0500 Subject: [PATCH 1/6] adjust to xcode .app file reuse --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m index ed2feee..dabdc6c 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m @@ -59,7 +59,7 @@ - (NSDictionary *) getHardCodedResponseForPageType:(NSString *)pageType { NSError *error; - NSString *filePath = [[NSBundle mainBundle] pathForResource:pageType ofType:@"json"]; + NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"JSON/%@", pageType] ofType:@"json"]; if (filePath) { return [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath] options:NSJSONReadingMutableContainers error:&error]; } From 291cf996042d3272d954cc18c99e8552c57554df Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Wed, 13 Dec 2023 14:10:52 -0500 Subject: [PATCH 2/6] HARD_CODED_RESPONSE_DELAY added to the up front request handling, --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 12d6014..5cc746a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -287,6 +287,9 @@ #if ENABLE_HARD_CODED_RESPONSE NSDictionary *response = [[MFHardCodedServerResponse sharedInstance] getHardCodedResponseForRequest:requestParameters]; +#if HARD_CODED_RESPONSE_DELAY > 0 + [NSThread sleepForTimeInterval:HARD_CODED_RESPONSE_DELAY]; +#endif if (response) { if (requestFinished) { requestFinished(response, nil); From c53bbd254bc1d35c4bdb66f29725c6265344156a Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 14 Dec 2023 15:57:37 -0500 Subject: [PATCH 3/6] bug fix for earlier OS versions --- .../MVMCore/ActionHandling/ActionShareHandler.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionShareHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionShareHandler.swift index 3634c11..cfaff2c 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionShareHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionShareHandler.swift @@ -27,9 +27,18 @@ open class ActionShareHandler: MVMCoreActionHandlerProtocol { // Activity was completed, considered finished. continuation.resume() } else if let error = error { + // Activity sharing failed. continuation.resume(throwing: error) } else { - continuation.resume() + // Activity was probably cancelled + if #available(iOS 16.4, *) { + continuation.resume() + } else if let _ = activityType { + // Pre iOS 16.4, this block gets called multiple times. Each time a specific activityType was selected and was cancelled, and when the whole share activity itself is cancelled. + return + } else { + continuation.resume() + } } } Task(priority: .high) { From 2e7fd9ddd43c333ea0a3c1f1432a1d6ca4679faf Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Tue, 19 Dec 2023 17:11:43 -0500 Subject: [PATCH 4/6] reposition after having a response --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 5cc746a..6591acd 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -287,10 +287,10 @@ #if ENABLE_HARD_CODED_RESPONSE NSDictionary *response = [[MFHardCodedServerResponse sharedInstance] getHardCodedResponseForRequest:requestParameters]; -#if HARD_CODED_RESPONSE_DELAY > 0 - [NSThread sleepForTimeInterval:HARD_CODED_RESPONSE_DELAY]; -#endif if (response) { + #if HARD_CODED_RESPONSE_DELAY > 0 + [NSThread sleepForTimeInterval:HARD_CODED_RESPONSE_DELAY]; + #endif if (requestFinished) { requestFinished(response, nil); } From b70220902a70690159cd9abc54441dd49c5a9228 Mon Sep 17 00:00:00 2001 From: "Rajendran, Nandhini" Date: Thu, 21 Dec 2023 16:29:40 +0000 Subject: [PATCH 5/6] story: ONEAPP-4156 LoggingHandler Swift migration --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 24 ++++---- .../ActionHandling/ActionOpenUrlHandler.swift | 2 +- .../ActionHandling/MVMCoreActionHandler.swift | 2 +- .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 4 +- .../MVMCoreLoadRequestOperation.m | 13 +++-- MVMCore/MVMCore/MVMCore.h | 5 +- .../MVMCoreLoggingDelegateProtocol.h | 27 --------- .../MVMCoreLoggingDelegateProtocol.swift | 24 ++++++++ .../ClientParameterHandler.swift | 4 +- .../MVMCore/Models/Model/ModelRegistry.swift | 2 +- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 9 ++- .../OtherHandlers/MVMCoreLoggingHandler.h | 31 ---------- .../OtherHandlers/MVMCoreLoggingHandler.m | 57 ------------------- .../OtherHandlers/MVMCoreLoggingHandler.swift | 41 +++++++++++++ .../MVMCoreLoggingHandlerHelper.h | 14 +++++ .../MFHardCodedServerResponse.m | 3 +- 16 files changed, 111 insertions(+), 151 deletions(-) delete mode 100644 MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h create mode 100644 MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.swift delete mode 100644 MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h delete mode 100644 MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m create mode 100644 MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift create mode 100644 MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index c0749ae..dbf0469 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -41,6 +41,9 @@ 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */; }; 2723337B28BD534D004EAEE0 /* MVMCoreEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */; }; 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */; }; + 6042E8FC2B317B190031644B /* MVMCoreLoggingHandlerHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6042E8FB2B3094680031644B /* MVMCoreLoggingHandlerHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 605A9A2A2ABD712F00487E47 /* MVMCoreLoggingHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 605A9A292ABD712F00487E47 /* MVMCoreLoggingHandler.swift */; }; + 6079EDCE2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6079EDCD2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift */; }; 60CBD0542A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60CBD0532A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift */; }; 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */; }; 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D26901FCC9D180079C521 /* MVMCoreOperation.m */; }; @@ -141,9 +144,6 @@ AFED77A61FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = AFED779E1FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m */; }; AFED77A71FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = AFED779F1FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m */; }; AFED77A81FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.h in Headers */ = {isa = PBXBuildFile; fileRef = AFED77A01FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AFEEE8191FCDEB8D00B5EDD0 /* MVMCoreLoggingDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFEEE8181FCDDE6B00B5EDD0 /* MVMCoreLoggingDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AFEEE81E1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = AFEEE81C1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AFEEE81F1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = AFEEE81D1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m */; }; AFFCFA651FCCC0D700FD0730 /* MVMCoreLoadingOverlayDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA611FCCC0D600FD0730 /* MVMCoreLoadingOverlayDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFFCFA661FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */; }; @@ -191,6 +191,9 @@ 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = ""; }; 581FABEE2A71D0E6003A8508 /* mvmcore_dev.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = mvmcore_dev.xcconfig; sourceTree = ""; }; 5836B8E22A4338DF002553D9 /* mvmcore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = mvmcore.xcconfig; sourceTree = ""; }; + 6042E8FB2B3094680031644B /* MVMCoreLoggingHandlerHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoggingHandlerHelper.h; sourceTree = ""; }; + 605A9A292ABD712F00487E47 /* MVMCoreLoggingHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreLoggingHandler.swift; sourceTree = ""; }; + 6079EDCD2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreLoggingDelegateProtocol.swift; sourceTree = ""; }; 60CBD0532A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreSessionTimeHandler.swift; sourceTree = ""; }; 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreErrorObject.m; sourceTree = ""; }; 881D26901FCC9D180079C521 /* MVMCoreOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreOperation.m; sourceTree = ""; }; @@ -297,9 +300,6 @@ AFED779E1FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreViewControllerStoryBoardMappingObject.m; sourceTree = ""; }; AFED779F1FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreViewControllerProgrammaticMappingObject.m; sourceTree = ""; }; AFED77A01FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerStoryBoardMappingObject.h; sourceTree = ""; }; - AFEEE8181FCDDE6B00B5EDD0 /* MVMCoreLoggingDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoggingDelegateProtocol.h; sourceTree = ""; }; - AFEEE81C1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoggingHandler.h; sourceTree = ""; }; - AFEEE81D1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreLoggingHandler.m; sourceTree = ""; }; AFFCFA611FCCC0D600FD0730 /* MVMCoreLoadingOverlayDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingOverlayDelegateProtocol.h; sourceTree = ""; }; AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingOverlayHandler.h; sourceTree = ""; }; AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreLoadingOverlayHandler.m; sourceTree = ""; }; @@ -517,7 +517,7 @@ D268D82926700292008BD413 /* MVMCoreViewManagerViewControllerProtocolHelper.h */, D268D82A26700292008BD413 /* MVMCoreViewManagerViewControllerProtocolHelper.m */, AF43A7401FC5FA6F008E9347 /* MVMCoreViewProtocol.h */, - AFEEE8181FCDDE6B00B5EDD0 /* MVMCoreLoggingDelegateProtocol.h */, + 6079EDCD2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift */, AF43A7001FC4B227008E9347 /* MVMCoreGlobalLoadProtocol.h */, ); path = MainProtocols; @@ -653,8 +653,8 @@ children = ( AF43A7091FC4F415008E9347 /* MVMCoreCache.h */, AF43A7081FC4F415008E9347 /* MVMCoreCache.m */, - AFEEE81C1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h */, - AFEEE81D1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m */, + 605A9A292ABD712F00487E47 /* MVMCoreLoggingHandler.swift */, + 6042E8FB2B3094680031644B /* MVMCoreLoggingHandlerHelper.h */, D288D5F426C6EFE000A5C365 /* MVMCoreLoggingHandler+Extension.swift */, 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */, ); @@ -710,6 +710,7 @@ AF43A7411FC5FA6F008E9347 /* MVMCoreViewProtocol.h in Headers */, AFBB96EC1FBA4A260008D868 /* MFHardCodedServerResponse.h in Headers */, AFBB96B21FBA3B590008D868 /* MVMCoreGetterUtility.h in Headers */, + 6042E8FC2B317B190031644B /* MVMCoreLoggingHandlerHelper.h in Headers */, 8876D5F21FB50AB000EB2E3D /* UIFont+MFSpacing.h in Headers */, 8876D5EC1FB50AB000EB2E3D /* NSDictionary+MFConvenience.h in Headers */, AFFCFA651FCCC0D700FD0730 /* MVMCoreLoadingOverlayDelegateProtocol.h in Headers */, @@ -732,7 +733,6 @@ 8876D5E81FB50AB000EB2E3D /* NSArray+MFConvenience.h in Headers */, AFBB96621FBA3A570008D868 /* MVMCoreRequestParameters.h in Headers */, AFBB96531FBA3A570008D868 /* MVMCoreLoadHandler.h in Headers */, - AFEEE81E1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h in Headers */, AF43A7011FC4B227008E9347 /* MVMCoreGlobalLoadProtocol.h in Headers */, AF43A5771FBA5B7C008E9347 /* MVMCoreJSONConstants.h in Headers */, AFBB96631FBA3A570008D868 /* MVMCoreLoadRequestOperation.h in Headers */, @@ -744,7 +744,6 @@ AFEA17A8209B6A1C00BC6740 /* MVMCoreBlockOperation.h in Headers */, AF43A5831FBB66DE008E9347 /* MVMCoreConstants.h in Headers */, AFED77A81FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.h in Headers */, - AFEEE8191FCDEB8D00B5EDD0 /* MVMCoreLoggingDelegateProtocol.h in Headers */, AF43A74C1FC6109F008E9347 /* MVMCoreSessionObject.h in Headers */, 8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */, AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */, @@ -865,6 +864,7 @@ 01F2A04C23A82B1B00D954D8 /* ActionCallModel.swift in Sources */, 8876D5ED1FB50AB000EB2E3D /* NSDictionary+MFConvenience.m in Sources */, AF686FDA2A8A876A008F666A /* NavigationOperation.swift in Sources */, + 605A9A2A2ABD712F00487E47 /* MVMCoreLoggingHandler.swift in Sources */, AFBB96ED1FBA4A260008D868 /* MFHardCodedServerResponse.m in Sources */, AF43A74D1FC6109F008E9347 /* MVMCoreSessionObject.m in Sources */, D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, @@ -882,6 +882,7 @@ 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 94C014D3242119E6005811A9 /* ActionPreviousSubmitModel.swift in Sources */, + 6079EDCE2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift in Sources */, AF60A7F2289212CA00919EEB /* MVMError.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, D27073B725BB45C4001C7246 /* ActionActionsModel.swift in Sources */, @@ -902,7 +903,6 @@ AF69D4F7286EA0B800BC6862 /* ActionPreviousSubmitHandler.swift in Sources */, AF43A57C1FBA5E6A008E9347 /* MVMCoreHardcodedStringsConstants.m in Sources */, 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */, - AFEEE81F1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m in Sources */, AF69D4F5286E9F5900BC6862 /* ActionSettingHandler.swift in Sources */, D27073CD25BB4CEF001C7246 /* MVMCoreActionHandler.swift in Sources */, 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift index 085b9a4..16ace45 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift @@ -82,7 +82,7 @@ open class ActionOpenUrlHandler: MVMCoreJSONActionHandlerProtocol { // Log error and continue MVMCoreLoggingHandler.shared()?.handleDebugMessage("Failed to open app url: \(appURL)") if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: model.actionType)) { - MVMCoreLoggingHandler.addError(toLog: errorObject) + MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject) } } } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index 7868be5..5d87fea 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -131,7 +131,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { /// Logs the error. @objc open func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable: Any]? = nil, delegateObject: DelegateObject? = nil) { guard error.logError else { return } - MVMCoreLoggingHandler.addError(toLog: error) + MVMCoreLoggingHandler.shared()?.addError(toLog: error) error.logError = false // Further attempts to log the same error will be skipped. (Legacy action flow.) } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 6591acd..4e39318 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -8,7 +8,6 @@ #import "MVMCoreLoadHandler.h" #import "MVMCoreGetterUtility.h" -#import "MVMCoreLoggingHandler.h" #import "MVMCoreLoadRequestOperation.h" #import "MVMCoreCache.h" #import "MFHardCodedServerResponse.h" @@ -20,6 +19,7 @@ #import "MVMCoreHardcodedStringsConstants.h" #import "MVMCoreConstants.h" #import "MVMCoreActionUtility.h" +#import "MVMCoreLoggingHandlerHelper.h" #import @interface MVMCoreLoadHandler () @@ -332,8 +332,6 @@ MVMCoreLog(@"Set-Cookie %@ Value: %@", requestParameters.pageType, [(NSHTTPURLResponse *)response allHeaderFields][@"Set-Cookie"]); - [MVMCoreLoggingHandler logWithDelegateWithObject:nil withName:@"httpRequestStatus" withExtraInfo:trackInfo]; - id jsonObject = nil; MVMCoreErrorObject *errorObject = nil; if (!error) { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index f0cc338..382c5ca 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -6,11 +6,11 @@ // Copyright © 2015 Verizon Wireless. All rights reserved. // +#import #import #import "MVMCoreLoadHandler.h" #import "MVMCoreLoadingOverlayHandler.h" #import "MVMCoreCache.h" -#import "MVMCoreLoggingHandler.h" #import "MVMCoreSessionObject.h" #import "MVMCoreViewControllerMappingObject.h" #import @@ -23,6 +23,7 @@ #import "MVMCoreErrorConstants.h" #import "MVMCoreActionUtility.h" #import "MVMCoreConstants.h" +#import "MVMCoreLoggingHandlerHelper.h" #import @interface MVMCoreLoadRequestOperation () @@ -555,13 +556,13 @@ if (error.errorScreenError) { error.silentError = NO; if (error.nativeDrivenErrorScreen) { - [MVMCoreLoggingHandler addErrorToLog:error]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:error]; } [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else if (!loadObject.requestParameters.dontDisplayViewController) { [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else { - [MVMCoreLoggingHandler addErrorToLog:error]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:error]; [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:viewController errorObject:error]; } } else if (!loadObject.requestParameters.shouldNotGoToServerOnCacheFail && (loadObject.pageDataFromCache || loadObject.moduleDataFromCache)) { @@ -573,7 +574,7 @@ loadObject.operation.errorForAlertToShow = nil; [loadObject.operation main]; } else { - [MVMCoreLoggingHandler addErrorToLog:error]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:error]; // Otherwise the request is finished. [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:error]; } @@ -723,7 +724,7 @@ // Logs the error. if (errorObject) { - [MVMCoreLoggingHandler addErrorToLog:errorObject]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:errorObject]; } }]; @@ -803,7 +804,7 @@ // Logs the error. If its a native driven error screen postpone until the native screen is define with its messaging. if (error.logError && !error.nativeDrivenErrorScreen) { - [MVMCoreLoggingHandler addErrorToLog:error]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:error]; } } diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index 1f56b24..c955683 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -67,11 +67,8 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; #import #import #import -#import - -// Other Handlers and Protocols -#import // Singletons #import #import +#import diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h deleted file mode 100644 index fc0e353..0000000 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// MVMCoreLoggingDelegateProtocol.h -// MVMCore -// -// Created by Pfeil, Scott Robert on 11/28/17. -// Copyright © 2017 myverizon. All rights reserved. -// - -#import - -@protocol MVMCoreLoggingDelegateProtocol - -@optional - -// Can be used to log different actions performed by the core. -- (void)handleDebugMessage:(nullable NSString *)message; - -// Can be used to log different actions performed by the core. -- (void)logWithObject:(nullable id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra; - -// Can be used to choose how to log error objects. -- (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject; - -// Log that the load has finished. -- (void)logLoadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController *)loadedViewController error:(nullable MVMCoreErrorObject *)error; - -@end diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.swift b/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.swift new file mode 100644 index 0000000..eb6f223 --- /dev/null +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.swift @@ -0,0 +1,24 @@ +// +// MVMCoreLoggingDelegateProtocol.swift +// MVMCore +// +// Created by Nandhini Rajendran on 13/10/23. +// Copyright © 2023 myverizon. All rights reserved. +// + +public protocol MVMCoreLoggingDelegateProtocol { + + // Can be used to log different actions performed by the core. + func handleDebugMessage(_ message: String?) + + // Can be used to choose how to log error objects. + func addError(toLog errorObject: MVMCoreErrorObject) + + // Log that the load has finished. + func logLoadFinished(_ loadObject: MVMCoreLoadObject?, loadedViewController: MVMCoreViewControllerProtocol?, error: MVMCoreErrorObject?) +} + +public extension MVMCoreLoggingDelegateProtocol { + func addError(toLog errorObject: MVMCoreErrorObject) {} + func logLoadFinished(_ loadObject: MVMCoreLoadObject?, loadedViewController: MVMCoreViewControllerProtocol?, error: MVMCoreErrorObject?) {} +} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift index 6f8c7e0..6e6b01e 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift @@ -16,7 +16,7 @@ return parameterType.init(clientParameterModel) } catch { if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) { - MVMCoreLoggingHandler.addError(toLog: errorObject) + MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject) } return nil } @@ -109,7 +109,7 @@ return } guard returnedList[index] == nil else { - MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!) + MVMCoreLoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!) return } MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId)) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 6e6e77a..e3cbd1c 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -103,7 +103,7 @@ public struct ModelRegistry { errorObject.title = "Unknown Model Registry Error" } - MVMCoreLoggingHandler.addError(toLog: errorObject) + MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject) #if DEBUG triggerCrashInDebug() #endif diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 74aa41f..8c43b9e 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -9,14 +9,13 @@ #import "MVMCoreCache.h" #import #import "MVMCoreErrorObject.h" -#import "MVMCoreLoggingHandler.h" +#import #import "MVMCoreGetterUtility.h" #import "MVMCoreConstants.h" #import "MVMCoreActionUtility.h" -#import "MVMCoreLoggingHandler.h" #import "MVMCoreDispatchUtility.h" #import "MVMCoreErrorConstants.h" -#import +#import "MVMCoreLoggingHandlerHelper.h" @interface MVMCoreCache () @@ -593,9 +592,9 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; //need to manually store cache for response [sharedCache storeCachedResponse:cachedReponse forRequest:request]; } else if (error) { - [MVMCoreLoggingHandler addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreCache->downloadImage"]]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreCache->downloadImage"]]; } else { - [MVMCoreLoggingHandler addErrorToLog:[[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[NSString stringWithFormat:@"Failed to download image %@", request.URL.absoluteString] code:0 domain:ErrorDomainSystem location:@"MVMCoreCache->downloadImage"]]; + [[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:[[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[NSString stringWithFormat:@"Failed to download image %@", request.URL.absoluteString] code:0 domain:ErrorDomainSystem location:@"MVMCoreCache->downloadImage"]]; } if (isGif) { [self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler]; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h deleted file mode 100644 index 4cd0b53..0000000 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// MVMCoreLoggingHandler.h -// MVMCore -// -// Created by Pfeil, Scott Robert on 11/28/17. -// Copyright © 2017 myverizon. All rights reserved. -// - -#import -#import -#import -#import -#import - -#define MVMCoreLog(fmt, ...) \ -[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]]; - -@interface MVMCoreLoggingHandler : NSObject - -+ (nullable instancetype)sharedLoggingHandler; - -+ (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject; -+ (void)logDebugMessageWithDelegate:(nullable NSString *)message; -+ (void)logWithDelegateWithObject:(nullable id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra; -+ (void)logWithDelegateLoadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController *)loadedViewController error:(nullable MVMCoreErrorObject *)error; -- (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes; - -#pragma mark MVMCoreLoggingDelegateProtocol -- (void)handleDebugMessage:(nullable NSString *)message; - -@end diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m deleted file mode 100644 index 2931aef..0000000 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m +++ /dev/null @@ -1,57 +0,0 @@ -// -// MVMCoreLoggingHandler.m -// MVMCore -// -// Created by Pfeil, Scott Robert on 11/28/17. -// Copyright © 2017 myverizon. All rights reserved. -// - -#import "MVMCoreLoggingHandler.h" -#import "MVMCoreActionUtility.h" -#import - -@implementation MVMCoreLoggingHandler - -+ (nullable instancetype)sharedLoggingHandler { - if ([MVMCoreObject sharedInstance].loggingDelegate && [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].loggingDelegate.class otherClass:self throwException:NO]) { - return (MVMCoreLoggingHandler *)[MVMCoreObject sharedInstance].loggingDelegate; - } else { - return nil; - } -} - -+ (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject { - if (errorObject && [[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(addErrorToLog:)]) { - [[MVMCoreObject sharedInstance].loggingDelegate addErrorToLog:errorObject]; - } -} - -+ (void)logDebugMessageWithDelegate:(nullable NSString *)message { - if (message && [[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(handleDebugMessage:)]) { - [[MVMCoreObject sharedInstance].loggingDelegate handleDebugMessage:message]; - } -} - -+ (void)logWithDelegateWithObject:(id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra { - if ([[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(logWithObject:withName:withExtraInfo:)]) { - [[MVMCoreObject sharedInstance].loggingDelegate logWithObject:object withName:name withExtraInfo:extra]; - } -} - -+ (void)logWithDelegateLoadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController *)loadedViewController error:(nullable MVMCoreErrorObject *)error { - if ([[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(logLoadFinished:loadedViewController:error:)]) { - [[MVMCoreObject sharedInstance].loggingDelegate logLoadFinished:loadObject loadedViewController:loadedViewController error:error]; - } -} - -- (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes {} - -#pragma mark - logging delegate - -- (void)handleDebugMessage:(nullable NSString *)message { -#ifdef LOGGING - [self printWith:message]; -#endif -} - -@end diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift new file mode 100644 index 0000000..afe5fc1 --- /dev/null +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift @@ -0,0 +1,41 @@ +// +// MVMCoreLoggingHandler.swift +// MVMCore +// +// Created by Nandhini Rajendran on 22/09/23. +// Copyright © 2023 myverizon. All rights reserved. +// + +import Foundation + +@objc open class MVMCoreLoggingHandler: NSObject, MVMCoreLoggingDelegateProtocol { + + @objc(sharedLoggingHandler) + public static func shared() -> Self? { + return MVMCoreActionUtility.initializerClassCheck(MVMCoreObject.sharedInstance()?.loggingDelegate as? NSObject, classToVerify: self) as? Self + } + + @objc public class func logDebugMessage(withDelegate message: String) { + MVMCoreObject.sharedInstance()?.loggingDelegate?.handleDebugMessage(message) + } + + @objc(logWithDelegateLoadFinished:loadedViewController:error:) + public class func log(withDelegateLoadFinished loadObject: MVMCoreLoadObject?, loadedViewController: UIViewController?, error: MVMCoreErrorObject?) { + MVMCoreObject.sharedInstance()?.loggingDelegate?.logLoadFinished(loadObject, loadedViewController: loadedViewController as? MVMCoreViewControllerProtocol, error: error) + } + + func recordEvent(_ name: String, attributes: [String : Any]?) {} + + // MARK: - logging delegate + @objc public func handleDebugMessage(_ message: String?) { + #if LOGGING + guard let message = message else { return } + self.print(with: message) + #endif + } + + @objc(addErrorToLog:) + open func addError(toLog errorObject: MVMCoreErrorObject) { + MVMCoreObject.sharedInstance()?.loggingDelegate?.addError(toLog: errorObject) + } +} diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h new file mode 100644 index 0000000..bb0fe9b --- /dev/null +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h @@ -0,0 +1,14 @@ +// +// MVMCoreLoggingHandlerHelper.h +// MVMCore +// +// Created by Nandhini Rajendran on 18/12/23. +// Copyright © 2023 myverizon. All rights reserved. +// + +#ifndef MVMCoreLoggingHandlerHelper_h +#define MVMCoreLoggingHandlerHelper_h +#define MVMCoreLog(fmt, ...) \ +[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]]; +#endif + diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m index dabdc6c..44b7b4d 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.m @@ -9,7 +9,8 @@ #import "MFHardCodedServerResponse.h" #import "MVMCoreRequestParameters.h" #import "NSDictionary+MFConvenience.h" -#import "MVMCoreLoggingHandler.h" +#import +#import "MVMCoreLoggingHandlerHelper.h" #if ENABLE_HARD_CODED_RESPONSE From 6d169ea203e146a20facbe5863eb0c8f7fdd1b17 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Tue, 2 Jan 2024 17:10:46 -0500 Subject: [PATCH 6/6] add collection safe subscript for index out of bound safety --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 ++++ MVMCore/MVMCore/Categories/Collection+Safe.swift | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 MVMCore/MVMCore/Categories/Collection+Safe.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index dbf0469..da71c4e 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */; }; 2723337B28BD534D004EAEE0 /* MVMCoreEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */; }; 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */; }; + 5846ABF42B44BB9000FA6C76 /* Collection+Safe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846ABF32B44BB9000FA6C76 /* Collection+Safe.swift */; }; 6042E8FC2B317B190031644B /* MVMCoreLoggingHandlerHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6042E8FB2B3094680031644B /* MVMCoreLoggingHandlerHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 605A9A2A2ABD712F00487E47 /* MVMCoreLoggingHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 605A9A292ABD712F00487E47 /* MVMCoreLoggingHandler.swift */; }; 6079EDCE2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6079EDCD2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift */; }; @@ -191,6 +192,7 @@ 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = ""; }; 581FABEE2A71D0E6003A8508 /* mvmcore_dev.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = mvmcore_dev.xcconfig; sourceTree = ""; }; 5836B8E22A4338DF002553D9 /* mvmcore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = mvmcore.xcconfig; sourceTree = ""; }; + 5846ABF32B44BB9000FA6C76 /* Collection+Safe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Safe.swift"; sourceTree = ""; }; 6042E8FB2B3094680031644B /* MVMCoreLoggingHandlerHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoggingHandlerHelper.h; sourceTree = ""; }; 605A9A292ABD712F00487E47 /* MVMCoreLoggingHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreLoggingHandler.swift; sourceTree = ""; }; 6079EDCD2AD97AA5004B7A85 /* MVMCoreLoggingDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreLoggingDelegateProtocol.swift; sourceTree = ""; }; @@ -408,6 +410,7 @@ 8876D5D91FB50AB000EB2E3D /* Categories */ = { isa = PBXGroup; children = ( + 5846ABF32B44BB9000FA6C76 /* Collection+Safe.swift */, 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */, D282AAB72240342D00C46919 /* NSNumber+Extension.swift */, 8876D5DA1FB50AB000EB2E3D /* NSArray+MFConvenience.h */, @@ -900,6 +903,7 @@ AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */, AFED77A61FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m in Sources */, 016CF36925FA6DD400B82A1F /* ClientParameterHandler.swift in Sources */, + 5846ABF42B44BB9000FA6C76 /* Collection+Safe.swift in Sources */, AF69D4F7286EA0B800BC6862 /* ActionPreviousSubmitHandler.swift in Sources */, AF43A57C1FBA5E6A008E9347 /* MVMCoreHardcodedStringsConstants.m in Sources */, 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */, diff --git a/MVMCore/MVMCore/Categories/Collection+Safe.swift b/MVMCore/MVMCore/Categories/Collection+Safe.swift new file mode 100644 index 0000000..0943a9d --- /dev/null +++ b/MVMCore/MVMCore/Categories/Collection+Safe.swift @@ -0,0 +1,16 @@ +// +// Collection+Safe.swift +// MVMCore +// +// Created by Kyle on 2/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension Collection { + /// Returns the element at the specified index if it is within bounds, otherwise nil. + subscript (safe index: Index) -> Element? { + return indices.contains(index) ? self[index] : nil + } +}