【发布时间】:2016-01-07 09:09:57
【问题描述】:
我正在使用 https://github.com/hyperoslo/Sync 和 Alamofire 向 api 发出 Get 请求。这段代码应该通过 Sync 存储在 Core Data 中。我的代码如下。
Alamofire.request(.GET, url + "users/getOwnUser", headers:headers).responseJSON { response in
switch response.result {
case .Success(let data):
let user = data.valueForKey("user")!
let kk = [user]
print(kk)
Sync.changes(kk, inEntityNamed: "User", dataStack: self.dataStack, completion: { (response ) -> Void in
print("USER \(response)")
})
case .Failure(let error):
print("Request failed with error: \(error)")
}
}
print(kk) 处的打印响应是
[{
challenges = "<null>";
created = "<null>";
credentials = "<null>";
email = "henry@hardy.com";
emailVerified = "<null>";
id = 6;
lastUpdated = "2016-01-04T01:53:22.000Z";
"phone_number" = "<null>";
pin = "<null>";
"pin_status" = "<null>";
"push_options" = 0;
"push_toggle" = 0;
"push_token" = "<null>";
realm = "<null>";
status = "<null>";
username = henryhardy;
verificationToken = "<null>";
}]
这似乎与这里的创建者提供的示例具有相同的结构。
[
{
"id": 6,
"name": "Shawn Merrill",
"email": "shawn@ovium.com",
"created_at": "2014-02-14T04:30:10+00:00",
"updated_at": "2014-02-17T10:01:12+00:00",
"notes": [
{
"id": 0,
"text": "Shawn Merril's diary, episode 1",
"created_at": "2014-03-11T19:11:00+00:00",
"updated_at": "2014-04-18T22:01:00+00:00"
}
]
}
]
减去分号与逗号。有没有人有任何经验让 alamofire 和 sync 玩得很好?周围似乎有一些人遇到了这个问题。谢谢!
编辑:Sync.changes 函数的响应是它是 nil。
【问题讨论】:
-
有一个与 Alamofire 同步的例子。 github.com/3lvis/SyncAppNetDemo
-
想知道你是怎么做到的吗?我遇到了完全相同的问题,但没有找到任何解决方案。对象的“id”可以很好地同步,但如果其他 int 属性来自带有下划线的服务器,则显示为 nil,例如“correlation_id”。布尔值以及同步为 0 或 1。