Add NSError versions of some methods default tip
authorDave Dribin <dave@dribin.org>
Sat Oct 18 16:36:03 2008 -0500 (2008-10-18)
changeset 110e70cc8e854e
parent 10 b705126fd40e
Add NSError versions of some methods
lib/DDCoreDataStack.h
lib/DDCoreDataStack.m
     1.1 --- a/lib/DDCoreDataStack.h	Sat Oct 18 15:27:56 2008 -0500
     1.2 +++ b/lib/DDCoreDataStack.h	Sat Oct 18 16:36:03 2008 -0500
     1.3 @@ -38,13 +38,22 @@
     1.4  @property (readonly, retain) NSPersistentStore * mainStore;
     1.5  @property (readonly, retain) NSManagedObjectContext * mainContext;
     1.6  
     1.7 +- (BOOL)createFullStackWithStoreType:(NSString *)storeType
     1.8 +                                 URL:(NSURL *)url
     1.9 +                               error:(NSError **)error;
    1.10 +
    1.11 +- (BOOL)createFullStackFromModelsInBundles:(NSArray *)bundles
    1.12 +                                 storeType:(NSString *)storeType
    1.13 +                                       URL:(NSURL *)url
    1.14 +                                     error:(NSError **)error;
    1.15 +
    1.16 +- (void)createFullStackWithStoreType:(NSString *)storeType
    1.17 +                                 URL:(NSURL *)url;
    1.18 +
    1.19  - (void)createFullStackFromModelsInBundles:(NSArray *)bundles
    1.20                                   storeType:(NSString *)storeType
    1.21                                         URL:(NSURL *)url;
    1.22  
    1.23 -- (void)createFullStackWithStoreType:(NSString *)storeType
    1.24 -                                 URL:(NSURL *)url;
    1.25 -
    1.26  - (void)destroyFullStack;
    1.27  
    1.28  - (void)createMergedModelFromMainBundle;
    1.29 @@ -62,6 +71,12 @@
    1.30                           URL:(NSURL *)url
    1.31                       options:(NSDictionary *)options;
    1.32  
    1.33 +- (BOOL)addMainStoreWithType:(NSString *)storeType
    1.34 +               configuration:(NSString *)configuration
    1.35 +                         URL:(NSURL *)url
    1.36 +                     options:(NSDictionary *)options
    1.37 +                       error:(NSError **)error;
    1.38 +
    1.39  - (void)removeMainStore;
    1.40  
    1.41  - (void)createMainContext;
     2.1 --- a/lib/DDCoreDataStack.m	Sat Oct 18 15:27:56 2008 -0500
     2.2 +++ b/lib/DDCoreDataStack.m	Sat Oct 18 16:36:03 2008 -0500
     2.3 @@ -39,6 +39,46 @@
     2.4      [super dealloc];
     2.5  }
     2.6  
     2.7 +- (BOOL)createFullStackWithStoreType:(NSString *)storeType
     2.8 +                                 URL:(NSURL *)url
     2.9 +                               error:(NSError **)error;
    2.10 +{
    2.11 +    return [self createFullStackFromModelsInBundles:nil
    2.12 +                                          storeType:storeType
    2.13 +                                                URL:url
    2.14 +                                              error:error];
    2.15 +}
    2.16 +
    2.17 +- (BOOL)createFullStackFromModelsInBundles:(NSArray *)bundles
    2.18 +                                 storeType:(NSString *)storeType
    2.19 +                                       URL:(NSURL *)url
    2.20 +                                     error:(NSError **)error;
    2.21 +{
    2.22 +    [self createMergedModelFromBundles:bundles];
    2.23 +    [self createCoordinator];
    2.24 +    if (![self addMainStoreWithType:storeType
    2.25 +                      configuration:nil
    2.26 +                                URL:url
    2.27 +                            options:nil
    2.28 +                              error:error])
    2.29 +    {
    2.30 +        [self destroyCoordinator];
    2.31 +        [self destroyModel];
    2.32 +        return NO;
    2.33 +    }
    2.34 +    
    2.35 +    [self createMainContext];
    2.36 +    return YES;
    2.37 +}
    2.38 +
    2.39 +- (void)createFullStackWithStoreType:(NSString *)storeType
    2.40 +                                 URL:(NSURL *)url;
    2.41 +{
    2.42 +    [self createFullStackFromModelsInBundles:nil
    2.43 +                                   storeType:storeType
    2.44 +                                         URL:url];
    2.45 +}
    2.46 +
    2.47  - (void)createFullStackFromModelsInBundles:(NSArray *)bundles
    2.48                                   storeType:(NSString *)storeType
    2.49                                         URL:(NSURL *)url;
    2.50 @@ -52,18 +92,6 @@
    2.51      [self createMainContext];
    2.52  }
    2.53  
    2.54 -- (void)createFullStackWithStoreType:(NSString *)storeType
    2.55 -                                 URL:(NSURL *)url;
    2.56 -{
    2.57 -    [self createMergedModelFromMainBundle];
    2.58 -    [self createCoordinator];
    2.59 -    [self addMainStoreWithType:storeType
    2.60 -                 configuration:nil
    2.61 -                           URL:url
    2.62 -                       options:nil];
    2.63 -    [self createMainContext];
    2.64 -}
    2.65 -
    2.66  - (void)destroyFullStack;
    2.67  {
    2.68      [self destroyMainContext];
    2.69 @@ -109,20 +137,36 @@
    2.70                           URL:(NSURL *)url
    2.71                       options:(NSDictionary *)options;
    2.72  {
    2.73 +    NSError * error = nil;
    2.74 +    if (![self addMainStoreWithType:storeType
    2.75 +                      configuration:configuration
    2.76 +                                URL:url
    2.77 +                            options:options
    2.78 +                              error:&error])
    2.79 +    {
    2.80 +        @throw [DDCoreDataException exceptionWithReason:@"Could not addPersistent store"
    2.81 +                                                  error:error];
    2.82 +    }
    2.83 +}
    2.84 +
    2.85 +- (BOOL)addMainStoreWithType:(NSString *)storeType
    2.86 +               configuration:(NSString *)configuration
    2.87 +                         URL:(NSURL *)url
    2.88 +                     options:(NSDictionary *)options
    2.89 +                       error:(NSError **)error;
    2.90 +{
    2.91      NSAssert(_mainStore == nil, @"Main store is already created");
    2.92      NSAssert(_coordinator != nil, @"Coordinator should not be nil");
    2.93 -    NSError * error = nil;
    2.94      _mainStore = [_coordinator addPersistentStoreWithType:storeType
    2.95                                              configuration:configuration
    2.96                                                        URL:url
    2.97                                                    options:options
    2.98 -                                                    error:&error];
    2.99 +                                                    error:error];
   2.100 +    [_mainStore retain];
   2.101      if (_mainStore == nil)
   2.102 -    {
   2.103 -        @throw [DDCoreDataException exceptionWithReason:@"Could not addPersistent store"
   2.104 -                                                  error:error];
   2.105 -    }
   2.106 -    [_mainStore retain];
   2.107 +        return NO;
   2.108 +    else
   2.109 +        return YES;
   2.110  }
   2.111  
   2.112  - (void)removeMainStore