Created
August 16, 2017 16:39
-
-
Save alobanov/8c32dfcb7c2648276eee0efdc85bc9bf to your computer and use it in GitHub Desktop.
This file contains 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 pred = NSPredicate(format: "slug = 'default'") | |
if let item: FolderData = databaseProvider.firstObject(type: DataModelType.folderData, predicate: pred) { | |
let realm = RealmConfigurator.shared.reamInstance() | |
try! realm.write { | |
item.mapping(map: Map(mappingType: .fromJSON, JSON: ["test": "Whaaaat?"])) | |
} | |
} | |
This file contains 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
class FolderData: ObjectMappable, PonsoConvertibleProtocol { | |
dynamic var slug: String? | |
dynamic var title = "" | |
dynamic var test = "" | |
var statuses = List<StatusData>() | |
required convenience init?(map: Map) { | |
self.init() | |
} | |
// Mappable | |
override func mapping(map: Map) { | |
super.mapping(map: map) | |
if map.mappingType == .fromJSON { | |
if slug == nil { | |
slug <- map["slug"] | |
} | |
} else { | |
slug >>> map["slug"] | |
} | |
title <- map["title"] | |
statuses <- (map["statuses"], ListTransform<StatusData>()) | |
test <- map["test"] | |
} | |
override class func primaryKey() -> String { | |
return "slug" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Обновится только значение Test. Значение Title останется прежним