UIManagedDocument and Master Data

I found these Stanford tutorials https://itunes.apple.com/us/course/ipad-iphone-app-development/id495052415 and listened to a lecture on basic data, which is really great.

It shows how to access the master data through UIManagedDocument... The only thing I don’t understand is how it UIManagedDocumentknows which model it should use, because I don’t see it anywhere?

To summarize it when used UIManagedDocument, how do you define the database model to be used?

+5
source share
2 answers

I found the answer:

'UIManagedDocument' . , .

, UIManagedDocument.

+6

. OS X, NSPersistentDocument . Xcode , Core Data ( OS X iOS), . , , , . Core Data , , .

, :

URL-, initWithContentsOfURL:. . , . URL-, modelByMergingModels: .

, , , , , ( ). , , URL- .

, mergedModelFromBundles:. , - , , , , . , , , , , .

    NSManagedObjectModel *model = <#Get a model#>;
NSFetchRequest *requestTemplate = [[NSFetchRequest alloc] init];
NSEntityDescription *publicationEntity =
    [[model entitiesByName] objectForKey:@"Publication"];
[requestTemplate setEntity:publicationEntity];

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat:
    @"(mainAuthor.firstName like[cd] $FIRST_NAME) AND \
        (mainAuthor.lastName like[cd] $LAST_NAME) AND \
        (publicationDate > $DATE)"];
[requestTemplate setPredicate:predicateTemplate];

[model setFetchRequestTemplate:requestTemplate
    forName:@"PublicationsForAuthorSinceDate"];

NSManagedObjectModel *model = <#Get a model#>;
NSError *error = nil;
NSDictionary *substitutionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
    @"Fiona", @"FIRST_NAME", @"Verde", @"LAST_NAME",
    [NSDate dateWithTimeIntervalSinceNow:-31356000], @"DATE", nil];
NSFetchRequest *fetchRequest =
    [model fetchRequestFromTemplateWithName:@"PublicationsForAuthorSinceDate"
            substitutionVariables:substitutionDictionary];
NSArray *results =
    [aManagedObjectContext executeFetchRequest:fetchRequest error:&error];
+1

All Articles