From c94a54cfa9273bcfe3ffca1ef798db952a43c417 Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Wed, 9 Apr 2025 13:25:29 +0200 Subject: [PATCH] useless Codable --- .../other_plugins/NotificationTracking.swift | 6 +++--- Sources/Segment/Analytics.swift | 4 ++-- Sources/Segment/Events.swift | 20 +++++++++---------- Sources/Segment/Settings.swift | 4 ++-- Sources/Segment/Utilities/JSON.swift | 4 ++-- .../Segment/Utilities/Storage/Storage.swift | 6 +++--- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Examples/other_plugins/NotificationTracking.swift b/Examples/other_plugins/NotificationTracking.swift index 294adbab..72e23687 100644 --- a/Examples/other_plugins/NotificationTracking.swift +++ b/Examples/other_plugins/NotificationTracking.swift @@ -42,7 +42,7 @@ class NotificationTracking: Plugin { var type: PluginType = .utility weak var analytics: Analytics? - func trackNotification(_ properties: [String: Codable], fromLaunch launch: Bool) { + func trackNotification(_ properties: [String: Encodable], fromLaunch launch: Bool) { if launch { analytics?.track(name: "Push Notification Tapped", properties: properties) } else { @@ -55,7 +55,7 @@ class NotificationTracking: Plugin { // determination if a push notification caused the app to open. extension NotificationTracking: RemoteNotifications { func receivedRemoteNotification(userInfo: [AnyHashable: Any]) { - if let notification = userInfo as? [String: Codable] { + if let notification = userInfo as? [String: Encodable] { trackNotification(notification, fromLaunch: false) } } @@ -88,7 +88,7 @@ import UIKit extension NotificationTracking: iOSLifecycle { func application(_ application: UIApplication?, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) { - if let notification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Codable] { + if let notification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Encodable] { trackNotification(notification, fromLaunch: true) } } diff --git a/Sources/Segment/Analytics.swift b/Sources/Segment/Analytics.swift index aec6c59c..ff96e632 100644 --- a/Sources/Segment/Analytics.swift +++ b/Sources/Segment/Analytics.swift @@ -239,7 +239,7 @@ extension Analytics { } /// Returns the traits that were specified in the last identify call. - public func traits() -> T? { + public func traits() -> T? { if let userInfo: UserInfo = store.currentState() { return userInfo.traits.codableValue() } @@ -385,7 +385,7 @@ extension Analytics { } ``` */ - public func openURL(_ url: URL, options: T? = nil) { + public func openURL(_ url: URL, options: T? = nil) { guard let jsonProperties = try? JSON(with: options) else { return } guard let dict = jsonProperties.dictionaryValue else { return } openURL(url, options: dict) diff --git a/Sources/Segment/Events.swift b/Sources/Segment/Events.swift index 77c5db5f..8c68b339 100644 --- a/Sources/Segment/Events.swift +++ b/Sources/Segment/Events.swift @@ -19,7 +19,7 @@ extension Analytics { /// - name: Name of the action, e.g., 'Purchased a T-Shirt' /// - properties: Properties specific to the named event. For example, an event with /// the name 'Purchased a Shirt' might have properties like revenue or size. - public func track(name: String, properties: P?) { + public func track(name: String, properties: P?) { do { if let properties = properties { let jsonProperties = try JSON(with: properties) @@ -50,7 +50,7 @@ extension Analytics { /// generate the UUID and Apple's policies on IDs, see /// https://segment.io/libraries/ios#ids /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. - public func identify(userId: String, traits: T?) { + public func identify(userId: String, traits: T?) { do { if let traits = traits { let jsonTraits = try JSON(with: traits) @@ -70,7 +70,7 @@ extension Analytics { /// Associate a user with their unique ID and record traits about them. /// - Parameters: /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. - public func identify(traits: T) { + public func identify(traits: T) { do { let jsonTraits = try JSON(with: traits) store.dispatch(action: UserInfo.SetTraitsAction(traits: jsonTraits)) @@ -93,7 +93,7 @@ extension Analytics { process(incomingEvent: event) } - public func screen(title: String, category: String? = nil, properties: P?) { + public func screen(title: String, category: String? = nil, properties: P?) { do { if let properties = properties { let jsonProperties = try JSON(with: properties) @@ -112,7 +112,7 @@ extension Analytics { screen(title: title, category: category, properties: nil as ScreenEvent?) } - public func group(groupId: String, traits: T?) { + public func group(groupId: String, traits: T?) { do { if let traits = traits { let jsonTraits = try JSON(with: traits) @@ -234,7 +234,7 @@ extension Analytics { /// - properties: Properties specific to the named event. For example, an event with /// the name 'Purchased a Shirt' might have properties like revenue or size. /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none. - public func track(name: String, properties: P?, enrichments: [EnrichmentClosure]?) { + public func track(name: String, properties: P?, enrichments: [EnrichmentClosure]?) { do { if let properties = properties { let jsonProperties = try JSON(with: properties) @@ -287,7 +287,7 @@ extension Analytics { /// https://segment.io/libraries/ios#ids /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none. - public func identify(userId: String, traits: T?, enrichments: [EnrichmentClosure]?) { + public func identify(userId: String, traits: T?, enrichments: [EnrichmentClosure]?) { do { if let traits = traits { let jsonTraits = try JSON(with: traits) @@ -308,7 +308,7 @@ extension Analytics { /// - Parameters: /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none. - public func identify(traits: T, enrichments: [EnrichmentClosure]?) { + public func identify(traits: T, enrichments: [EnrichmentClosure]?) { do { let jsonTraits = try JSON(with: traits) store.dispatch(action: UserInfo.SetTraitsAction(traits: jsonTraits)) @@ -366,7 +366,7 @@ extension Analytics { /// - category: A category to the type of screen if it applies. /// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc. /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none. - public func screen(title: String, category: String? = nil, properties: P?, enrichments: [EnrichmentClosure]?) { + public func screen(title: String, category: String? = nil, properties: P?, enrichments: [EnrichmentClosure]?) { do { if let properties = properties { let jsonProperties = try JSON(with: properties) @@ -411,7 +411,7 @@ extension Analytics { process(incomingEvent: event, enrichments: enrichments) } - public func group(groupId: String, traits: T?, enrichments: [EnrichmentClosure]?) { + public func group(groupId: String, traits: T?, enrichments: [EnrichmentClosure]?) { do { if let traits = traits { let jsonTraits = try JSON(with: traits) diff --git a/Sources/Segment/Settings.swift b/Sources/Segment/Settings.swift index 1cc1abca..67da48b8 100644 --- a/Sources/Segment/Settings.swift +++ b/Sources/Segment/Settings.swift @@ -76,7 +76,7 @@ public struct Settings: Codable { return result } - public func integrationSettings(forKey key: String) -> T? { + public func integrationSettings(forKey key: String) -> T? { var result: T? = nil guard let settings = integrations?.dictionaryValue else { return nil } if let dict = settings[key], let jsonData = try? JSONSerialization.data(withJSONObject: dict) { @@ -85,7 +85,7 @@ public struct Settings: Codable { return result } - public func integrationSettings(forPlugin plugin: DestinationPlugin) -> T? { + public func integrationSettings(forPlugin plugin: DestinationPlugin) -> T? { return integrationSettings(forKey: plugin.key) } diff --git a/Sources/Segment/Utilities/JSON.swift b/Sources/Segment/Utilities/JSON.swift index 510cc917..4d118cbe 100644 --- a/Sources/Segment/Utilities/JSON.swift +++ b/Sources/Segment/Utilities/JSON.swift @@ -73,7 +73,7 @@ public enum JSON: Equatable { } // For Value types - public init(with value: T) throws { + public init(with value: T) throws { let encoder = JSONSafeEncoder.default let json = try encoder.encode(value) let output = try JSONSerialization.jsonObject(with: json, options: .fragmentsAllowed) @@ -222,7 +222,7 @@ extension JSON { return result as Any } - public func codableValue() -> T? { + public func codableValue() -> T? { var result: T? = nil if let dict = dictionaryValue, let jsonData = try? JSONSerialization.data(withJSONObject: dict) { do { diff --git a/Sources/Segment/Utilities/Storage/Storage.swift b/Sources/Segment/Utilities/Storage/Storage.swift index 3cd37432..681bc00f 100644 --- a/Sources/Segment/Utilities/Storage/Storage.swift +++ b/Sources/Segment/Utilities/Storage/Storage.swift @@ -57,7 +57,7 @@ internal class Storage: Subscriber { } } - func write(_ key: Storage.Constants, value: T?) { + func write(_ key: Storage.Constants, value: T?) { switch key { case .events: if let event = value as? RawEvent { @@ -98,7 +98,7 @@ internal class Storage: Subscriber { return nil } - func read(_ key: Storage.Constants) -> T? { + func read(_ key: Storage.Constants) -> T? { var result: T? = nil switch key { case .events: @@ -134,7 +134,7 @@ internal class Storage: Subscriber { } } - func isBasicType(value: T?) -> Bool { + func isBasicType(value: T?) -> Bool { var result = false if value == nil { result = true