I just found out about Parse's Local Data Store and it looks like a SQL database that handles online/offline syncing.
I'm writing an application for a client who wants something similar to the contacts app. Contacts can be added/edited offline, or added on a different device, and they all need to sync properly and not create duplicate entities.
Is using Parse Local Data Store a viable option?
I do this in the App Delegate did finish launching with options method:
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
PFObject.pinAllInBackground(objects, block: nil)
}
} else {
println("Error: \(error!) \(error!.userInfo!)")
}
}
Then in my initial view controller I do this:
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
self.athleteArray = objects
self.tableView.reloadData()
}
} else {
println("Error: \(error!) \(error!.userInfo!)")
}
}
However, I assume because the App Delegate query runs in the background, the data store hasn't received objects when the view controller runs because the tableview shows up empty.
When I launch the app again later, the objects are there because the data store has been populated.
How can I manage syncing objects (in real-time, no second app launching) using Parse's Local Data Store? Am I doing something incorrectly?