Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import CoreData
import Foundation
import GenericJSON
import OptimoveCore

final class EventCDv1ToEventCDv2MigrationPolicy: NSEntityMigrationPolicy {
Expand Down
138 changes: 0 additions & 138 deletions OptimoveSDK/Sources/Classes/JSON/Initialization.swift

This file was deleted.

61 changes: 61 additions & 0 deletions OptimoveSDK/Sources/Classes/JSON/JSON+init.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright © 2023 Optimove. All rights reserved.

import Foundation
import GenericJSON

extension JSON {
// Convenience initializer to convert from [String: Any]
init?(dictionary: [String: Any]) {
var jsonDict = [String: JSON]()

for (key, value) in dictionary {
if let stringValue = value as? String {
jsonDict[key] = JSON.string(stringValue)
} else if let intValue = value as? Int {
jsonDict[key] = JSON.number(Double(intValue))
} else if let doubleValue = value as? Double {
jsonDict[key] = JSON.number(doubleValue)
} else if let boolValue = value as? Bool {
jsonDict[key] = JSON.bool(boolValue)
} else if let dictValue = value as? [String: Any] {
jsonDict[key] = JSON(dictionary: dictValue)
} else if let arrayValue = value as? [Any] {
jsonDict[key] = JSON(array: arrayValue)
} else {
// For unsupported types, you can either skip or handle them differently
// Skipping here
Logger.error("Skipping unsupported type: \(type(of: value))")
continue
}
}

self = JSON.object(jsonDict)
}

// Helper to convert an array
private init?(array: [Any]) {
var jsonArray: [JSON] = []

for value in array {
if let stringValue = value as? String {
jsonArray.append(JSON.string(stringValue))
} else if let intValue = value as? Int {
jsonArray.append(JSON.number(Double(intValue)))
} else if let doubleValue = value as? Double {
jsonArray.append(JSON.number(doubleValue))
} else if let boolValue = value as? Bool {
jsonArray.append(JSON.bool(boolValue))
} else if let dictValue = value as? [String: Any] {
jsonArray.append(JSON(dictionary: dictValue)!)
} else if let arrayValue = value as? [Any] {
jsonArray.append(JSON(array: arrayValue)!)
} else {
// Handle unsupported types
Logger.error("Skipping unsupported type: \(type(of: value))")
continue
}
}

self = JSON.array(jsonArray)
}
}
102 changes: 0 additions & 102 deletions OptimoveSDK/Sources/Classes/JSON/JSON.swift

This file was deleted.

63 changes: 0 additions & 63 deletions OptimoveSDK/Sources/Classes/JSON/Merging.swift

This file was deleted.

Loading