Skip to content

Instantly share code, notes, and snippets.

@fadion
Created April 12, 2017 14:16
Show Gist options
  • Save fadion/0be69887dc1899d6615e0c9f26fa0716 to your computer and use it in GitHub Desktop.
Save fadion/0be69887dc1899d6615e0c9f26fa0716 to your computer and use it in GitHub Desktop.
let realm = try! Realm()
let json = JSON(self.data)["pizza"].array
let viewModels = json.map { item -> PizzaViewModel in
let model = Pizza()
model.id = item["id"].intValue
model.name = item["name"].stringValue
model.price = item["price"].intValue
try! realm.write {
realm.add(model, update: true)
}
return PizzaViewModel(model: model)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment