From 68a5bf8dd01a98b6908d5e4cb0ae38d55a993fd5 Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Tue, 11 Jul 2023 13:00:48 -0700 Subject: [PATCH] Remove unneeded guard --- MixpanelServiceKit/MixpanelService.swift | 34 +++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/MixpanelServiceKit/MixpanelService.swift b/MixpanelServiceKit/MixpanelService.swift index 765f381..777dbc0 100644 --- a/MixpanelServiceKit/MixpanelService.swift +++ b/MixpanelServiceKit/MixpanelService.swift @@ -64,24 +64,7 @@ public final class MixpanelService: Service { extension MixpanelService: AnalyticsService { public func recordAnalyticsEvent(_ name: String, withProperties properties: [AnyHashable: Any]?, outOfSession: Bool) { - guard let properties else { - return - } - - var mappedProperties: [String: MixpanelType] = [:] - for (key, value) in properties { - guard let key = key as? String else { - return - } - - guard let value = value as? MixpanelType else { - return - } - - mappedProperties[key] = value - } - - client?.track(event: name, properties: mappedProperties) + client?.track(event: name, properties: mappedProperties(from: properties)) } public func recordIdentify(_ property: String, value: String) { @@ -106,3 +89,18 @@ extension KeychainManager { } fileprivate let MixpanelTokenService = "MixpanelToken" + +private extension MixpanelService { + func mappedProperties(from properties: [AnyHashable: Any]?) -> [String: MixpanelType] { + guard let properties else { return [:] } + var mappedProperties: [String: MixpanelType] = [:] + + for (key, value) in properties { + if let key = key as? String, let value = value as? MixpanelType { + mappedProperties[key] = value + } + } + + return mappedProperties + } +}