I'm using https://github.com/hyperoslo/Sync and Alamofire to make a Get request to an api. This code is supposed to then be store in Core Data through Sync. The code that I have is below.
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)")
}
}
The response from the print at print(kk) is
[{
challenges = "<null>";
created = "<null>";
credentials = "<null>";
email = "[email protected]";
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>";
}]
which seems to have the same structure as the example provided by the creators here.
[
{
"id": 6,
"name": "Shawn Merrill",
"email": "[email protected]",
"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"
}
]
}
]
minus the semicolons vs the commas. Does anyone have any experience getting alamofire and sync to play nice? There appears to be a few people around who are experiencing this issue. Thanks!
EDIT: The response that the Sync.changes function is that it is nil.
This framework has been deprecated, but here is a link to a repo that has an example of how it's done - https://github.com/3lvis/AppNetDemo - Thank you to 3lvis for the pointers.