Skip to content

Commit bcc4277

Browse files
useless Codable (#386)
1 parent 5d3a762 commit bcc4277

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

Examples/other_plugins/NotificationTracking.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class NotificationTracking: Plugin {
4242
var type: PluginType = .utility
4343
weak var analytics: Analytics?
4444

45-
func trackNotification(_ properties: [String: Codable], fromLaunch launch: Bool) {
45+
func trackNotification(_ properties: [String: Encodable], fromLaunch launch: Bool) {
4646
if launch {
4747
analytics?.track(name: "Push Notification Tapped", properties: properties)
4848
} else {
@@ -55,7 +55,7 @@ class NotificationTracking: Plugin {
5555
// determination if a push notification caused the app to open.
5656
extension NotificationTracking: RemoteNotifications {
5757
func receivedRemoteNotification(userInfo: [AnyHashable: Any]) {
58-
if let notification = userInfo as? [String: Codable] {
58+
if let notification = userInfo as? [String: Encodable] {
5959
trackNotification(notification, fromLaunch: false)
6060
}
6161
}
@@ -88,7 +88,7 @@ import UIKit
8888

8989
extension NotificationTracking: iOSLifecycle {
9090
func application(_ application: UIApplication?, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
91-
if let notification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Codable] {
91+
if let notification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Encodable] {
9292
trackNotification(notification, fromLaunch: true)
9393
}
9494
}

Sources/Segment/Analytics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ extension Analytics {
242242
}
243243

244244
/// Returns the traits that were specified in the last identify call.
245-
public func traits<T: Codable>() -> T? {
245+
public func traits<T: Decodable>() -> T? {
246246
if let userInfo: UserInfo = store.currentState() {
247247
return userInfo.traits.codableValue()
248248
}
@@ -388,7 +388,7 @@ extension Analytics {
388388
}
389389
```
390390
*/
391-
public func openURL<T: Codable>(_ url: URL, options: T? = nil) {
391+
public func openURL<T: Encodable>(_ url: URL, options: T? = nil) {
392392
guard let jsonProperties = try? JSON(with: options) else { return }
393393
guard let dict = jsonProperties.dictionaryValue else { return }
394394
openURL(url, options: dict)

Sources/Segment/Events.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Analytics {
1919
/// - name: Name of the action, e.g., 'Purchased a T-Shirt'
2020
/// - properties: Properties specific to the named event. For example, an event with
2121
/// the name 'Purchased a Shirt' might have properties like revenue or size.
22-
public func track<P: Codable>(name: String, properties: P?) {
22+
public func track<P: Encodable>(name: String, properties: P?) {
2323
do {
2424
if let properties = properties {
2525
let jsonProperties = try JSON(with: properties)
@@ -50,7 +50,7 @@ extension Analytics {
5050
/// generate the UUID and Apple's policies on IDs, see
5151
/// https://segment.io/libraries/ios#ids
5252
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
53-
public func identify<T: Codable>(userId: String, traits: T?) {
53+
public func identify<T: Encodable>(userId: String, traits: T?) {
5454
do {
5555
if let traits = traits {
5656
let jsonTraits = try JSON(with: traits)
@@ -70,7 +70,7 @@ extension Analytics {
7070
/// Associate a user with their unique ID and record traits about them.
7171
/// - Parameters:
7272
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
73-
public func identify<T: Codable>(traits: T) {
73+
public func identify<T: Encodable>(traits: T) {
7474
do {
7575
let jsonTraits = try JSON(with: traits)
7676
store.dispatch(action: UserInfo.SetTraitsAction(traits: jsonTraits))
@@ -93,7 +93,7 @@ extension Analytics {
9393
process(incomingEvent: event)
9494
}
9595

96-
public func screen<P: Codable>(title: String, category: String? = nil, properties: P?) {
96+
public func screen<P: Encodable>(title: String, category: String? = nil, properties: P?) {
9797
do {
9898
if let properties = properties {
9999
let jsonProperties = try JSON(with: properties)
@@ -112,7 +112,7 @@ extension Analytics {
112112
screen(title: title, category: category, properties: nil as ScreenEvent?)
113113
}
114114

115-
public func group<T: Codable>(groupId: String, traits: T?) {
115+
public func group<T: Encodable>(groupId: String, traits: T?) {
116116
do {
117117
if let traits = traits {
118118
let jsonTraits = try JSON(with: traits)
@@ -234,7 +234,7 @@ extension Analytics {
234234
/// - properties: Properties specific to the named event. For example, an event with
235235
/// the name 'Purchased a Shirt' might have properties like revenue or size.
236236
/// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
237-
public func track<P: Codable>(name: String, properties: P?, enrichments: [EnrichmentClosure]?) {
237+
public func track<P: Encodable>(name: String, properties: P?, enrichments: [EnrichmentClosure]?) {
238238
do {
239239
if let properties = properties {
240240
let jsonProperties = try JSON(with: properties)
@@ -287,7 +287,7 @@ extension Analytics {
287287
/// https://segment.io/libraries/ios#ids
288288
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
289289
/// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
290-
public func identify<T: Codable>(userId: String, traits: T?, enrichments: [EnrichmentClosure]?) {
290+
public func identify<T: Encodable>(userId: String, traits: T?, enrichments: [EnrichmentClosure]?) {
291291
do {
292292
if let traits = traits {
293293
let jsonTraits = try JSON(with: traits)
@@ -308,7 +308,7 @@ extension Analytics {
308308
/// - Parameters:
309309
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
310310
/// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
311-
public func identify<T: Codable>(traits: T, enrichments: [EnrichmentClosure]?) {
311+
public func identify<T: Encodable>(traits: T, enrichments: [EnrichmentClosure]?) {
312312
do {
313313
let jsonTraits = try JSON(with: traits)
314314
store.dispatch(action: UserInfo.SetTraitsAction(traits: jsonTraits))
@@ -366,7 +366,7 @@ extension Analytics {
366366
/// - category: A category to the type of screen if it applies.
367367
/// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc.
368368
/// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
369-
public func screen<P: Codable>(title: String, category: String? = nil, properties: P?, enrichments: [EnrichmentClosure]?) {
369+
public func screen<P: Encodable>(title: String, category: String? = nil, properties: P?, enrichments: [EnrichmentClosure]?) {
370370
do {
371371
if let properties = properties {
372372
let jsonProperties = try JSON(with: properties)
@@ -411,7 +411,7 @@ extension Analytics {
411411
process(incomingEvent: event, enrichments: enrichments)
412412
}
413413

414-
public func group<T: Codable>(groupId: String, traits: T?, enrichments: [EnrichmentClosure]?) {
414+
public func group<T: Encodable>(groupId: String, traits: T?, enrichments: [EnrichmentClosure]?) {
415415
do {
416416
if let traits = traits {
417417
let jsonTraits = try JSON(with: traits)

Sources/Segment/Settings.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct Settings: Codable {
7676
return result
7777
}
7878

79-
public func integrationSettings<T: Codable>(forKey key: String) -> T? {
79+
public func integrationSettings<T: Decodable>(forKey key: String) -> T? {
8080
var result: T? = nil
8181
guard let settings = integrations?.dictionaryValue else { return nil }
8282
if let dict = settings[key], let jsonData = try? JSONSerialization.data(withJSONObject: dict) {
@@ -85,7 +85,7 @@ public struct Settings: Codable {
8585
return result
8686
}
8787

88-
public func integrationSettings<T: Codable>(forPlugin plugin: DestinationPlugin) -> T? {
88+
public func integrationSettings<T: Decodable>(forPlugin plugin: DestinationPlugin) -> T? {
8989
return integrationSettings(forKey: plugin.key)
9090
}
9191

Sources/Segment/Utilities/JSON.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public enum JSON: Equatable {
7373
}
7474

7575
// For Value types
76-
public init<T: Codable>(with value: T) throws {
76+
public init<T: Encodable>(with value: T) throws {
7777
let encoder = JSONSafeEncoder.default
7878
let json = try encoder.encode(value)
7979
let output = try JSONSerialization.jsonObject(with: json, options: .fragmentsAllowed)
@@ -222,7 +222,7 @@ extension JSON {
222222
return result as Any
223223
}
224224

225-
public func codableValue<T: Codable>() -> T? {
225+
public func codableValue<T: Decodable>() -> T? {
226226
var result: T? = nil
227227
if let dict = dictionaryValue, let jsonData = try? JSONSerialization.data(withJSONObject: dict) {
228228
do {

Sources/Segment/Utilities/Storage/Storage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal class Storage: Subscriber {
5757
}
5858
}
5959

60-
func write<T: Codable>(_ key: Storage.Constants, value: T?) {
60+
func write<T: Encodable>(_ key: Storage.Constants, value: T?) {
6161
switch key {
6262
case .events:
6363
if let event = value as? RawEvent {
@@ -98,7 +98,7 @@ internal class Storage: Subscriber {
9898
return nil
9999
}
100100

101-
func read<T: Codable>(_ key: Storage.Constants) -> T? {
101+
func read<T: Decodable>(_ key: Storage.Constants) -> T? {
102102
var result: T? = nil
103103
switch key {
104104
case .events:
@@ -134,7 +134,7 @@ internal class Storage: Subscriber {
134134
}
135135
}
136136

137-
func isBasicType<T: Codable>(value: T?) -> Bool {
137+
func isBasicType<T: Encodable>(value: T?) -> Bool {
138138
var result = false
139139
if value == nil {
140140
result = true

0 commit comments

Comments
 (0)