如何实现自定义类型的转换?

时间:2016-04-06 14:31:13

标签: ios swift

我正在使用Realm并且我创建了一个User模型。用户可以通过该应用注册。当他这样做时,我要做的就是POST我的User实例。

以下是我开始做的事情:

let params = currentUser as? Dictionary<String, AnyObject?>
octoClient.post("/users", options: params) { (data) in
    // ...
}

我正在寻找的是:

class User: Object {

    dynamic var id = ""
    dynamic var firstName = ""
    dynamic var lastName = ""
    dynamic var email = ""
    dynamic var phone = ""
    dynamic var postalCode = ""
    dynamic var state = ""
    dynamic var country = ""
    dynamic var city = ""
    dynamic var address = ""
    dynamic var category = List<Industry>()
    dynamic var birthday = NSDate()
    dynamic var password = ""
    dynamic var passwordConfirmation = ""
    let notifications = List<Notification>()
    dynamic var privateToken = ""
    dynamic var createdAt = NSDate()

    func toDictionary() -> [String: AnyObject?] {
        // format current instance to wanted format
        return [String: AnyObject?]()
    }
}

0 个答案:

没有答案