Skip to content

Commit

Permalink
Use a resources bundle to store the data model in CocoaPods.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgulanowski committed Jun 29, 2016
1 parent 480bc51 commit 9ebfb1c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Mobile Buy SDK/Mobile Buy SDK/Models/BUYModelManager.m
Expand Up @@ -39,6 +39,11 @@
NSString * const BUYFlatArrayTransformerName = @"BUYFlatArray";
NSString * const BUYProductTagsTransformerName = @"BUYProductTags";

@interface NSBundle (BUYAdditions)
+ (instancetype)frameworkBundle;
+ (instancetype)resourcesBundle;
@end

@interface BUYModelManager ()
@property (nonatomic, strong) NSManagedObjectModel *model;
@end
Expand All @@ -57,7 +62,7 @@ + (void)initialize

- (instancetype)init
{
return [self initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:@[[NSBundle bundleForClass:[self class]]]]];
return [self initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:@[[NSBundle resourcesBundle]]]];
}

- (instancetype)initWithManagedObjectModel:(NSManagedObjectModel *)model
Expand Down Expand Up @@ -120,3 +125,26 @@ - (BOOL)buy_purgeObjectsWithEntityName:(NSString *)entityName matchingPredicate:
}

@end

@implementation NSBundle (BUYAdditions)

+ (instancetype)frameworkBundle
{
return [NSBundle bundleForClass:[BUYModelManager class]];
}

+ (NSURL *)resourcesBundleURL
{
return [[self frameworkBundle] URLForResource:@"Buy" withExtension:@"bundle"];
}

+ (instancetype)resourcesBundle
{
#if COCOAPODS
return [NSBundle bundleWithURL:[self resourcesBundleURL]];
#else
return [self frameworkBundle];
#endif
}

@end

0 comments on commit 9ebfb1c

Please sign in to comment.