Wednesday, August 1, 2012

Core Data in easy steps - Tutorials step by step

Step 1: Manage xDataModel
1a : Add Entity
1b: Add Attribute
1c: Change Type

Step 2: Select the required entitie
2a: File --> New --> New File
2b: Under CoreData, select NSManagedObjectSubClass

Step 3: Select "AppDeligate.h"
3a: #import "entitie.h" - entitie is name of our selected entitie

Step 4: Create Data
4a: Make sure you use error logging because xcode does not report created by CoreData
4b:


NSManagedObjectContext *context = [self managedObjectContext];
    Login *detail = [NSEntityDescription insertNewObjectForEntityForName:@"Login" inManagedObjectContext:context];

    detail.userName = @"userName";
    detail.password = @"password";
    
    NSError *error;
    if (![context save:&error]) {
        NSLog(@"Error !");
    }
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Login" inManagedObjectContext:context];
    
    [request setEntity:entity];
    
    NSArray *arr = [context executeFetchRequest:request error:&error];
    
    for (PMLogin *ent in arr) {
        NSLog(@"name %@", ent.userName);
        NSLog(@"Number %@",ent.password);
    }




I'm using following book and video to learn Core Data in easy steps


Sams Teach Yourself Core Data for
iPhone Core Data 1-3

http://www.youtube.com/watch?v=QBrkavVJsw0&feature=relmfu
http://www.youtube.com/watch?v=DBNpUzhUAsg&feature=relmfu
http://www.youtube.com/watch?v=12UlRUnpp2I&feature=relmfu