Skip to content

Instantly share code, notes, and snippets.

@isoiphone
Created March 11, 2015 22:12
Show Gist options
  • Save isoiphone/4dc4cb6531b31998e8a7 to your computer and use it in GitHub Desktop.
Save isoiphone/4dc4cb6531b31998e8a7 to your computer and use it in GitHub Desktop.
handling realm.io errors on startup (lazy way to handle migration changes, missing encryption key, etc)
// this is the first call to defaultRealm() (ie: it lives in application:didFinishLaunchingWithOptions)
// see: SwiftTryCatch https://github.com/williamFalcon/SwiftTryCatch for a wrapper around ObjectiveC exceptions.
SwiftTryCatch.try({
RLMRealm.defaultRealm()
}, catch: { exception in
log.error("realm exception: \(exception.description). Will remove local database.")
NSFileManager.defaultManager().removeItemAtPath(RLMRealm.defaultRealmPath()!, error: nil)
SwiftTryCatch.try({
RLMRealm.defaultRealm()
}, catch: { exception in
log.error("realm exception on startup. Still not resolved.")
// TODO: analytics/log this to server
}, finally: {
})
}, finally: {
})
@isoiphone
Copy link
Author

ok, @simjp showed me this is a terrible idea.

@timanglade
Copy link

This project has about it a whiff of the quiet, almost understated elegance of the La Brea tar pits. I like it.
gloob

@isoiphone
Copy link
Author

^- this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment