Created
March 11, 2015 22:12
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: { | |
}) |
This project has about it a whiff of the quiet, almost understated elegance of the La Brea tar pits. I like it.
—gloob
^- this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok, @simjp showed me this is a terrible idea.