I'm building a toy app in iOS where the user can:
All of this using Core Data for persistence and Alamofire for networking, coded in Swift.
What I usually do for this flow is the following:
This requires that all of those tasks are executed serially, but Alamofire doesn't do synchronous requests apparently. I'm new to iOS programming, and I've read a little about GCD, but I'm not sure how should I proceed.
To clear this up with straightforward questions:
This is how I'd do it (assuming you can change the server's code):
First, store a local "sync date" somewhere in the app. Then, for every task, store a modified date. Whenever a task is modified, set the modified date to the current date. Then when you want to synchronise with the server:
For deleting tasks, I'd have a "deleted" flag on each task. When a task is deleted, it's "deleted" flag is set to true. It'll still be synchronised to the server, but if a task is downloaded from the server with the "deleted" flag set, it should be removed from the database...
GCD
As for GCD, it looks like that Alamofire library takes care of all that for you, so you don't need to use it. If you did want to use it, it is pretty simple:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND), ^{
// This code will run in the background, so it doesn't matter
// how long it takes, it won't freeze the app...
});
dispatch_async(dispatch_get_main_queue(), ^{
// This code will run on the main thread...
});
It also has a lot more features...