我有这个要求:
let manager = AFHTTPRequestOperationManager()
self.manager.POST(self.reservationsURL, parameters: reservation.parametersDictionary(), success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void in
var responseObject = (operation.responseObject as! Dictionary<String, AnyObject>)["data"] as! Dictionary<String, AnyObject>
// responseObject = ["source": 1,
// "name": "Rodolfo",
// "info": "",
// "id": 160,
// "created": "2015-08-24T21:00:29Z",
// "people": 3,
// "datetime": "2015-08-24T21:00:29Z",
// "status": 0,
// "mobile": "11999999000",
// "modified": "2015-08-24T21:00:29Z"]
self.realm.write { () -> Void in
self.realm.create(GIReservation.self, value: parsedData, update: true)
}
}) { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
println("OPS!\(operation.error)")
}
这个关于Realm的模型:
public class GIReservation: Object{
dynamic var name = ""
dynamic var mobile = ""
dynamic var datetime = NSDate()
dynamic var people = 0
dynamic var status = 0
dynamic var info = ""
dynamic var id = 0
dynamic var localID = NSUUID().UUIDString
dynamic var user: User?
public func parametersDictionary() -> Dictionary<String, AnyObject> {
var parameters: [String : AnyObject] = ["name": self.name, "mobile": self.mobile, "datetime" : self.datetime.toUTCISO8601String(), "people" : self.people, "status" : self.status]
if self.info.isEmpty {
parameters["info"] = self.info
}
return parameters
}
public override static func primaryKey() -> String? {
return "localID"
}
}
问题:
由于未捕获的异常'RLMException'而终止应用,原因:'属性'人'的'无效值'3'
同样的情况发生在任何其他不是String的地方,所以好吧,我已经检查过所有东西都返回了NCFString类型,无论是Int还是Date都无关紧要。
奇怪的是;当我用Objective-C和RLMObject尝试相同的东西时,它就像一个魅力。
JSON的内容类型是application / json。
任何想法发生了什么?