forked from magicalpanda/MagicalRecord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSManagedObjectModel+ActiveRecord.m
60 lines (47 loc) · 1.83 KB
/
NSManagedObjectModel+ActiveRecord.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
//
// NSManagedObjectModel+ActiveRecord.m
// DocBook
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
#import "NSManagedObjectModel+ActiveRecord.h"
static NSManagedObjectModel *defaultManagedObjectModel = nil;
@implementation NSManagedObjectModel (ActiveRecord)
+ (NSManagedObjectModel *)defaultManagedObjectModel
{
if (defaultManagedObjectModel == nil)
{
defaultManagedObjectModel = [self newManagedObjectModel];
}
return defaultManagedObjectModel;
}
+ (void) setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel
{
[defaultManagedObjectModel release];
defaultManagedObjectModel = [newDefaultModel retain];
}
+ (NSManagedObjectModel *) newManagedObjectModel
{
return [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
}
+ (NSManagedObjectModel *) newModelNamed:(NSString *) modelName inBundleNamed:(NSString *) bundleName
{
NSString *path = [[NSBundle mainBundle] pathForResource:[modelName stringByDeletingPathExtension]
ofType:[modelName pathExtension]
inDirectory:bundleName];
NSURL *modelUrl = [NSURL fileURLWithPath:path];
return [[NSManagedObjectModel alloc] initWithContentsOfURL:modelUrl];
}
+ (NSManagedObjectModel *) newManagedObjectModelNamed:(NSString *)modelFileName
{
NSString *path = [[NSBundle mainBundle] pathForResource:[modelFileName stringByDeletingPathExtension] ofType:[modelFileName pathExtension]];
NSURL *momURL = [NSURL fileURLWithPath:path];
NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
return model;
}
+ (NSManagedObjectModel *) managedObjectModelNamed:(NSString *)modelFileName
{
return [[self newManagedObjectModelNamed:modelFileName] autorelease];
}
@end