-
Notifications
You must be signed in to change notification settings - Fork 2
Sync vs Async
Jeff Hurray edited this page Apr 25, 2016
·
1 revision
Every method that is not executed in O(1) time has a background method associated with it (i.e. fetch and fetchInBackground, save and saveInBackground). Most of the sync methods throw, while the async methods have a completion block with an error as a parameter.
// Sync
let movies = try Movie.fetchAll()
// Async
Movie.fetchAllInBackground({ (movies, error) in
guard error == nil else{
// handle error
return
}
print("Fetched \(movies.count) movies.")
})##Differences
#####Threads: Sync methods execute on the current thread while Async methods execute on a background thread associated with the model
#####Error Handling:
Sync methods throw, while the async methods have a completion block with an SQLiteModelError as a parameter.
SQLiteModel