This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Realm | |
| import RealmSwift | |
| class CatPerson: Object, Decodable { | |
| @objc dynamic var personId: Int = 0 | |
| @objc dynamic var firstName: String = "" | |
| @objc dynamic var lastName: String = "" | |
| var cats = List<Cat>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let catsArray = try container.decode([Cat].self, forKey: .cats) | |
| let catsList = List<Cat>() | |
| catsList.append(objectsIn: catsArray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Realm | |
| import RealmSwift | |
| class CatPerson: Object, Decodable { | |
| @objc dynamic var personId: Int = 0 | |
| @objc dynamic var firstName: String = "" | |
| @objc dynamic var lastName: String = "" | |
| var cats = List<Cat>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "personId": 1, | |
| "firstName": "John", | |
| "lastName": "Smith", | |
| "cats": [ | |
| { | |
| "catId": 1, | |
| "name": "Ashes", | |
| "breed": "Bengal", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| po Realm.Configuration.defaultConfiguration.fileURL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
| let serializer = JSONSerializer() | |
| serializer.serialize(input: "Cats") | |
| return true | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import RealmSwift | |
| class JSONSerializer { | |
| func serialize(input sourceName: String) { | |
| let path = Bundle.main.path(forResource: sourceName, ofType: nil) | |
| let url = URL(fileURLWithPath: path!) | |
| let jsonDecoder = JSONDecoder() | |
| do { | |
| let data = try Data(contentsOf: url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Realm | |
| import RealmSwift | |
| class Cat: Object, Decodable { | |
| @objc dynamic var catId: Int = 0 | |
| @objc dynamic var name: String = "" | |
| @objc dynamic var breed: String = "" | |
| @objc dynamic var weight: Double = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Realm | |
| import RealmSwift | |
| class Cat: Object, Decodable { | |
| @objc dynamic var catId: Int = 0 | |
| @objc dynamic var name: String = "" | |
| @objc dynamic var breed: String = "" | |
| @objc dynamic var weight: Double = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "catId" : 1, | |
| "name": "Ashes", | |
| "breed": "Bengal", | |
| "weight" : 4.5 | |
| }, | |
| { | |
| "catId" : 2, | |
| "name": "Molly", |