Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit c61baf2

Browse files
committed
Re-indent
1 parent 50818cd commit c61baf2

34 files changed

+1818
-1818
lines changed

CoreDataKit/CDK.swift

+58-58
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import CoreData
1010

1111
public enum CDKLogLevel {
12-
case DEBUG
13-
case INFO
14-
case WARN
15-
case ERROR
12+
case DEBUG
13+
case INFO
14+
case WARN
15+
case ERROR
1616
}
1717

1818
public typealias Logger = (CDKLogLevel, String) -> Void
@@ -22,71 +22,71 @@ public typealias Logger = (CDKLogLevel, String) -> Void
2222
*/
2323
public class CDK : NSObject
2424
{
25-
private struct Holder {
26-
static var sharedStack: CoreDataStack?
27-
static var sharedLogger: Logger = { _, message in print("[CoreDataKit] \(message)") }
25+
private struct Holder {
26+
static var sharedStack: CoreDataStack?
27+
static var sharedLogger: Logger = { _, message in print("[CoreDataKit] \(message)") }
28+
}
29+
30+
/**
31+
Property to hold a shared instance of CoreDataStack, all the convenience class properties access and unwrap this shared instance. So make sure to set the shared instance before doing anything else.
32+
33+
:discussion: This is the only property you have to set to setup CoreDataKit, changing the shared instace is not supported.
34+
*/
35+
public class var sharedStack: CoreDataStack? {
36+
get {
37+
return Holder.sharedStack
2838
}
2939

30-
/**
31-
Property to hold a shared instance of CoreDataStack, all the convenience class properties access and unwrap this shared instance. So make sure to set the shared instance before doing anything else.
32-
33-
:discussion: This is the only property you have to set to setup CoreDataKit, changing the shared instace is not supported.
34-
*/
35-
public class var sharedStack: CoreDataStack? {
36-
get {
37-
return Holder.sharedStack
38-
}
39-
40-
set {
41-
Holder.sharedStack = newValue
42-
}
40+
set {
41+
Holder.sharedStack = newValue
4342
}
43+
}
4444

45-
/**
46-
Shared logger used by CoreDataKit to log messages.
47-
48-
:discussion: Default logger prints messages to console, but you can use this to use your own logger
49-
*/
50-
public class var sharedLogger: Logger {
51-
get {
52-
return Holder.sharedLogger
53-
}
54-
55-
set {
56-
Holder.sharedLogger = newValue
57-
}
58-
}
59-
60-
// MARK: Convenience properties
45+
/**
46+
Shared logger used by CoreDataKit to log messages.
6147

62-
/// Persistent store coordinator used as backing for the contexts of the shared stack
63-
public class var persistentStoreCoordinator: NSPersistentStoreCoordinator {
64-
return sharedStack!.persistentStoreCoordinator
48+
:discussion: Default logger prints messages to console, but you can use this to use your own logger
49+
*/
50+
public class var sharedLogger: Logger {
51+
get {
52+
return Holder.sharedLogger
6553
}
6654

67-
/// Child context of `rootContext` with concurrency type `PrivateQueueConcurrencyType`; Perform all read/write actions on this context
68-
public class var backgroundContext: NSManagedObjectContext {
69-
return sharedStack!.backgroundContext
55+
set {
56+
Holder.sharedLogger = newValue
7057
}
58+
}
7159

72-
/// Context with concurrency type `NSMainQueueConcurrencyType`; Use only for read actions directly tied to the UI (e.g. NSFetchedResultsController)
73-
public class var mainThreadContext: NSManagedObjectContext {
74-
return sharedStack!.mainThreadContext
75-
}
60+
// MARK: Convenience properties
7661

77-
/**
78-
Performs the given block on the `backgroundContect`
62+
/// Persistent store coordinator used as backing for the contexts of the shared stack
63+
public class var persistentStoreCoordinator: NSPersistentStoreCoordinator {
64+
return sharedStack!.persistentStoreCoordinator
65+
}
7966

80-
- parameter block: Block that performs the changes on the given context that should be saved
81-
- parameter completion: Completion block to run after changes are saved
67+
/// Child context of `rootContext` with concurrency type `PrivateQueueConcurrencyType`; Perform all read/write actions on this context
68+
public class var backgroundContext: NSManagedObjectContext {
69+
return sharedStack!.backgroundContext
70+
}
8271

83-
:see: NSManagedObjectContext.performBlock()
84-
*/
85-
public class func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
86-
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: completionHandler)
87-
}
72+
/// Context with concurrency type `NSMainQueueConcurrencyType`; Use only for read actions directly tied to the UI (e.g. NSFetchedResultsController)
73+
public class var mainThreadContext: NSManagedObjectContext {
74+
return sharedStack!.mainThreadContext
75+
}
8876

89-
public class func performBlockOnBackgroundContext(block: PerformBlock) {
90-
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: nil)
91-
}
77+
/**
78+
Performs the given block on the `backgroundContect`
79+
80+
- parameter block: Block that performs the changes on the given context that should be saved
81+
- parameter completion: Completion block to run after changes are saved
82+
83+
:see: NSManagedObjectContext.performBlock()
84+
*/
85+
public class func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
86+
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: completionHandler)
87+
}
88+
89+
public class func performBlockOnBackgroundContext(block: PerformBlock) {
90+
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: nil)
91+
}
9292
}

CoreDataKit/CoreDataStack.swift

+84-84
Original file line numberDiff line numberDiff line change
@@ -9,88 +9,88 @@
99
import CoreData
1010

1111
public class CoreDataStack: NSObject {
12-
/// Persistent store coordinator used as backing for the contexts
13-
public let persistentStoreCoordinator: NSPersistentStoreCoordinator
14-
15-
/// Root context that is directly associated with the `persistentStoreCoordinator` and does it work on a background queue; Do not use directly
16-
public let rootContext: NSManagedObjectContext
17-
18-
/// Context with concurrency type `NSMainQueueConcurrencyType`; Use only for read actions directly tied to the UI (e.g. NSFetchedResultsController)
19-
public let mainThreadContext: NSManagedObjectContext
20-
21-
/// Child context of `rootContext` with concurrency type `PrivateQueueConcurrencyType`; Perform all read/write actions on this context
22-
public let backgroundContext: NSManagedObjectContext
23-
24-
/**
25-
Create a stack based on the given `NSPersistentStoreCoordinator`.
26-
27-
- parameter persistentStoreCoordinator: The coordinator that will be coordinate the persistent store of this stack
28-
*/
29-
public init(persistentStoreCoordinator: NSPersistentStoreCoordinator) {
30-
self.persistentStoreCoordinator = persistentStoreCoordinator
31-
32-
self.rootContext = NSManagedObjectContext(persistentStoreCoordinator: self.persistentStoreCoordinator)
33-
self.rootContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
34-
35-
self.mainThreadContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType, parentContext: rootContext)
36-
37-
self.backgroundContext = self.mainThreadContext.createChildContext()
38-
39-
super.init()
40-
41-
// TODO: In de huidige setup, nobody cares, want main context zit tussen de saves in en krijgt vanzelf de notificaties
42-
//NSNotificationCenter.defaultCenter().addObserver(self, selector: "rootContextDidSave:", name: NSManagedObjectContextDidSaveNotification, object: rootContext)
43-
}
44-
45-
// deinit {
46-
// NSNotificationCenter.defaultCenter().removeObserver(self)
47-
// }
48-
49-
// MARK: Convenience methods
50-
51-
/**
52-
Performs the given block on the `backgroundContect`
53-
54-
- parameter block: Block that performs the changes on the given context that should be saved
55-
- parameter completion: Completion block to run after changes are saved
56-
57-
:see: NSManagedObjectContext.performBlock()
58-
*/
59-
public func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
60-
backgroundContext.performBlock(block, completionHandler: completionHandler)
61-
}
62-
63-
public func performBlockOnBackgroundContext(block: PerformBlock) {
64-
backgroundContext.performBlock(block, completionHandler: nil)
65-
}
66-
67-
/**
68-
Dumps some debug info about this stack to the console
69-
*/
70-
public func dumpStack() {
71-
CDK.sharedLogger(.DEBUG, "Stores: \(persistentStoreCoordinator.persistentStores)")
72-
CDK.sharedLogger(.DEBUG, " - Store coordinator: \(persistentStoreCoordinator.debugDescription)")
73-
CDK.sharedLogger(.DEBUG, " |- Root context: \(rootContext.debugDescription)")
74-
CDK.sharedLogger(.DEBUG, " |- Main thread context: \(mainThreadContext.debugDescription)")
75-
CDK.sharedLogger(.DEBUG, " |- Background context: \(backgroundContext.debugDescription)")
76-
}
77-
78-
// MARK: Notification observers
79-
80-
// func rootContextDidSave(notification: NSNotification) {
81-
// if NSThread.isMainThread() {
82-
// if let updatedObjects = notification.userInfo?[NSUpdatedObjectsKey] as? NSSet {
83-
// for _object in updatedObjects {
84-
// let object = _object as! NSManagedObject
85-
// mainThreadContext.objectWithID(object.objectID).willAccessValueForKey(nil)
86-
// }
87-
// }
88-
//
89-
// mainThreadContext.mergeChangesFromContextDidSaveNotification(notification)
90-
// } else {
91-
// dispatch_async(dispatch_get_main_queue()) {
92-
// self.rootContextDidSave(notification)
93-
// }
94-
// }
95-
// }
12+
/// Persistent store coordinator used as backing for the contexts
13+
public let persistentStoreCoordinator: NSPersistentStoreCoordinator
14+
15+
/// Root context that is directly associated with the `persistentStoreCoordinator` and does it work on a background queue; Do not use directly
16+
public let rootContext: NSManagedObjectContext
17+
18+
/// Context with concurrency type `NSMainQueueConcurrencyType`; Use only for read actions directly tied to the UI (e.g. NSFetchedResultsController)
19+
public let mainThreadContext: NSManagedObjectContext
20+
21+
/// Child context of `rootContext` with concurrency type `PrivateQueueConcurrencyType`; Perform all read/write actions on this context
22+
public let backgroundContext: NSManagedObjectContext
23+
24+
/**
25+
Create a stack based on the given `NSPersistentStoreCoordinator`.
26+
27+
- parameter persistentStoreCoordinator: The coordinator that will be coordinate the persistent store of this stack
28+
*/
29+
public init(persistentStoreCoordinator: NSPersistentStoreCoordinator) {
30+
self.persistentStoreCoordinator = persistentStoreCoordinator
31+
32+
self.rootContext = NSManagedObjectContext(persistentStoreCoordinator: self.persistentStoreCoordinator)
33+
self.rootContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
34+
35+
self.mainThreadContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType, parentContext: rootContext)
36+
37+
self.backgroundContext = self.mainThreadContext.createChildContext()
38+
39+
super.init()
40+
41+
// TODO: In de huidige setup, nobody cares, want main context zit tussen de saves in en krijgt vanzelf de notificaties
42+
//NSNotificationCenter.defaultCenter().addObserver(self, selector: "rootContextDidSave:", name: NSManagedObjectContextDidSaveNotification, object: rootContext)
43+
}
44+
45+
// deinit {
46+
// NSNotificationCenter.defaultCenter().removeObserver(self)
47+
// }
48+
49+
// MARK: Convenience methods
50+
51+
/**
52+
Performs the given block on the `backgroundContect`
53+
54+
- parameter block: Block that performs the changes on the given context that should be saved
55+
- parameter completion: Completion block to run after changes are saved
56+
57+
:see: NSManagedObjectContext.performBlock()
58+
*/
59+
public func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
60+
backgroundContext.performBlock(block, completionHandler: completionHandler)
61+
}
62+
63+
public func performBlockOnBackgroundContext(block: PerformBlock) {
64+
backgroundContext.performBlock(block, completionHandler: nil)
65+
}
66+
67+
/**
68+
Dumps some debug info about this stack to the console
69+
*/
70+
public func dumpStack() {
71+
CDK.sharedLogger(.DEBUG, "Stores: \(persistentStoreCoordinator.persistentStores)")
72+
CDK.sharedLogger(.DEBUG, " - Store coordinator: \(persistentStoreCoordinator.debugDescription)")
73+
CDK.sharedLogger(.DEBUG, " |- Root context: \(rootContext.debugDescription)")
74+
CDK.sharedLogger(.DEBUG, " |- Main thread context: \(mainThreadContext.debugDescription)")
75+
CDK.sharedLogger(.DEBUG, " |- Background context: \(backgroundContext.debugDescription)")
76+
}
77+
78+
// MARK: Notification observers
79+
80+
// func rootContextDidSave(notification: NSNotification) {
81+
// if NSThread.isMainThread() {
82+
// if let updatedObjects = notification.userInfo?[NSUpdatedObjectsKey] as? NSSet {
83+
// for _object in updatedObjects {
84+
// let object = _object as! NSManagedObject
85+
// mainThreadContext.objectWithID(object.objectID).willAccessValueForKey(nil)
86+
// }
87+
// }
88+
//
89+
// mainThreadContext.mergeChangesFromContextDidSaveNotification(notification)
90+
// } else {
91+
// dispatch_async(dispatch_get_main_queue()) {
92+
// self.rootContextDidSave(notification)
93+
// }
94+
// }
95+
// }
9696
}

0 commit comments

Comments
 (0)