Skip to content

Instantly share code, notes, and snippets.

@akramhussein
Created August 26, 2016 07:48
Show Gist options
  • Save akramhussein/46d6e8e73ad900125b03d0d3d8697584 to your computer and use it in GitHub Desktop.
Save akramhussein/46d6e8e73ad900125b03d0d3d8697584 to your computer and use it in GitHub Desktop.
Realm+ObjectMapper Example
import Foundation
import RealmSwift
import ObjectMapper
class Product: Object, Mappable
{
dynamic var name = ""
dynamic var price = 0.0
var discount = RealmOptional<Float>() {
willSet { self.discount = newValue }
}
// MARK: - JSON Mapping
required convenience init?(_ map: Map)
{
self.init()
self.mapping(map)
}
static func mapped(dict: [String : AnyObject]) -> Product
{
return Mapper<Product>().map(dict)! as Product
}
func mapping(map: Map)
{
name <- map["name"]
price <- map["price"]
discount.value <- map["discount"]
}
}
@MikhailovAl
Copy link

24 line: Argument labels '(_:)' do not match any available overloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment