Created
August 26, 2016 07:48
-
-
Save akramhussein/46d6e8e73ad900125b03d0d3d8697584 to your computer and use it in GitHub Desktop.
Realm+ObjectMapper Example
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 | |
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"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
24 line: Argument labels '(_:)' do not match any available overloads