/
MagicalRecord+iCloud.m
61 lines (51 loc) · 2.57 KB
/
MagicalRecord+iCloud.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// MagicalRecord+iCloud.m
// Magical Record
//
// Created by Saul Mora on 3/7/12.
// Copyright (c) 2012 Magical Panda Software LLC. All rights reserved.
//
#import "MagicalRecord+iCloud.h"
#import "NSPersistentStoreCoordinator+MagicalRecord.h"
#import "NSManagedObjectContext+MagicalRecord.h"
static BOOL _iCloudEnabled = NO;
@implementation MagicalRecord (iCloud)
#pragma mark - iCloud Methods
+ (BOOL) isICloudEnabled;
{
return _iCloudEnabled;
}
+ (void) setICloudEnabled:(BOOL)enabled;
{
@synchronized(self)
{
_iCloudEnabled = enabled;
}
}
+ (void) setupCoreDataStackWithiCloudContainer:(NSString *)icloudBucket localStoreNamed:(NSString *)localStore;
{
NSString *contentNameKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleIdentifierKey];
[self setupCoreDataStackWithiCloudContainer:icloudBucket
contentNameKey:contentNameKey
localStoreNamed:localStore
cloudStorePathComponent:nil];
}
+ (void) setupCoreDataStackWithiCloudContainer:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)pathSubcomponent;
{
[self setupCoreDataStackWithiCloudContainer:containerID
contentNameKey:contentNameKey
localStoreNamed:localStoreName
cloudStorePathComponent:pathSubcomponent
completion:nil];
}
+ (void) setupCoreDataStackWithiCloudContainer:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)pathSubcomponent completion:(void(^)(void))completion;
{
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithiCloudContainerID:containerID
contentNameKey:contentNameKey
localStoreNamed:localStoreName
cloudStorePathComponent:pathSubcomponent
completion:completion];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
}
@end