From e42f18644dd8c3917c2a9c6c41fc6153ec7a19e4 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 3 Jun 2015 01:42:08 +0900 Subject: [PATCH] Created Logging and error handling (markdown) --- Logging-and-error-handling.md | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Logging-and-error-handling.md diff --git a/Logging-and-error-handling.md b/Logging-and-error-handling.md new file mode 100644 index 0000000..45e909e --- /dev/null +++ b/Logging-and-error-handling.md @@ -0,0 +1,38 @@ +One unfortunate thing when using some third-party libraries is that they usually pollute the console with their own logging mechanisms. CoreStore provides it's own default logging class, but you can plug-in your own favorite logger by implementing the `CoreStoreLogger` protocol. +```swift +final class MyLogger: CoreStoreLogger { + func log(#level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + // pass to your logger + } + + func handleError(#error: NSError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + // pass to your logger + } + + func assert(@autoclosure condition: () -> Bool, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + // pass to your logger + } +} +``` +Then pass an instance of this class to `CoreStore`: +```swift +CoreStore.logger = MyLogger() +``` +Doing so channels all logging calls to your logger. + +Note that to keep the call stack information intact, all calls to these methods are not thread-managed. Thus you have to make sure that your logger is thread-safe or you may otherwise have to dispatch your logging implementation to a serial queue. + +## Observing changes and notifications +CoreStore provides type-safe wrappers for observing managed objects: + +- `ManagedObjectController`: use to observe changes to a single `NSManagedObject` instance (instead of Key-Value Observing) +- `ManagedObjectListController`: use to observe changes to a list of `NSManagedObject` instances (instead of `NSFetchedResultsController`) + + +## Contents +- [[Architecture]] +- [[Setting up]] +- [[Saving and processing transactions]] +- [[Fetching and querying]] +- [[Logging and error handling]] +- [[Observing changes and notifications]]