I’ve decided to break my blog down into four sections so that I cover the topics I intend to each week. First will be “Progress” where I highlight the things I learned this week. Next will be “Reading” where I talk about what I am currently studying. Following that will be “Quick Looks” where I talk about some technologies I briefly researched during the week. Finally I will have “News” where I will talk about news that caught my eye this week. So without further ado, here goes:
Progress
I didn’t make as much progress as I had hoped this week. I did add Marcus Zarra’s CoreDataStack design to my project. It was pretty straight forward. Here is the initialization in Swift:
init(dbName:String, syncToCloud:Bool, completion: ((Void) -> Void)? ) {
modelName = dbName
// Get the Model
let bundle = NSBundle.mainBundle()
let modelURL = bundle.URLForResource(dbName, withExtension: "momd")
let _model = NSManagedObjectModel(contentsOfURL: modelURL!)
assert(_model != nil, "Could not retrieve model at URL \(modelURL)")
model = _model!
// Build the persistent store coordinator
psc = NSPersistentStoreCoordinator(managedObjectModel: model)
// Set up the main MOC
mainQueueMOC = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
// Create the private MOC, this is the parent context of the mainQueueMOC and it
// owns the persistent store.
privateMOC = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
privateMOC.persistentStoreCoordinator = psc
// Make the main MOC a child of the private MOC
mainQueueMOC.parentContext = privateMOC
// Attach the basic life cycle listeners
attachInternalListeners()
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
// Get the proper options dictionary and storeURL based on the state
// of our sync flag.
var storeURL:NSURL?
var options:[NSObject: AnyObject]?
if (syncToCloud) {
storeURL = self.cloudStoreURL
if (self.rebuildFromCloudStore) {
options = self.cloudStoreOptionsWithRebuild
}
else {
options = self.cloudStoreOptions
}
}
else {
options = self.localStoreOptions
storeURL = self.localStoreURL
}
var error: NSError? = nil
self.store = self.psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL!, options: options!, error: &error)
assert(self.store != nil, "Could not add store URL \(storeURL)")
if let _completion = completion {
dispatch_async(dispatch_get_main_queue(),_completion)
}
}
}
Where I got tripped up is in running the deduplication algorithm. It worked but after migrating the store to iCloud then running the deduplication code and standing up a new NSFetchedResultsController I get the following error:
CoreData: Ubiquity: Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=5 "The operation couldn’t be completed. (BRCloudDocsErrorDomain error 5 - No document at URL)"
Doing a few google searches I found that others are also seeing this error, but so far there is no answer. I’m not sure this is really the error that is causing all the issues. What I am seeing in my test app is if I include the deduplication code in the code path after the store is migrated (whether that be to the cloud or to local store) my app hangs right when I try to update the fetched results for my UITableView. And yes, I am on the main queue when it happens so I know that is not the problem.
I’m also still running across folks giving up on CoreData and iCloud syncing so my decision to continue this investigation seems a little shakey. I just wished I knew what they were moving to, since the problem of sync’d data seems like a required feature in today’s apps. I do not want to stand up my own server to do this (although I am entirely capable of doing it) because I don’t want to incur the recurring cost for an app that might not be able to pay the server costs.
Reading
I am currently reading Spring in Action from Manning Publishing. I’m about a third of the way through and it appears to be very thorough. I need to work on a test app to apply what I am learning
News That Caught My Eye
Well the Apple Watch was opened for pre-order this past Friday. I was up with the intent of buying one, but in the end I decided against it. At least for now. I think I can get buy with the simulator as the supply chain gets filled and the first real users start reporting on it.
Quick Looks
I intended to look at React this past week, but ran out of cycles. Maybe next week.
No comments:
Post a Comment