Alamofire JSON响应不能被Hyperoslo Sync使用

时间:2016-01-07 09:09:58

标签: json swift alamofire

我使用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)")
            }
        }

印刷品(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.changes功能的响应是它是零。

1 个答案:

答案 0 :(得分:0)

该框架已被弃用,但是这里有一个仓库的链接,上面有一个如何完成的示例-https://github.com/3lvis/AppNetDemo-感谢3lvis提供的指针。