我正在尝试CoreData
在ios
应用程序中实现,现在我想从实体中获取所有记录MUSTHAFA
My NSManagedObjectedSubClass is MUSTAHFA
MUSTHAFA.m
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface MUSTHAFA : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * FirstName;
@property (nonatomic, retain) NSNumber * Age;
@property (nonatomic, retain) NSString * Location;
@property (nonatomic, retain) NSString * LastName;
@end
#import "MUSTHAFA.h"
@implementation MUSTHAFA
@dynamic FirstName;
@dynamic Age;
@dynamic Location;
@dynamic LastName;
@end
向核心数据添加记录
-(void)AddRecordToCoreData{
//NSLog(@"______ ADD Core Data Implementaion");
MUSTHAFA *event = (MUSTHAFA *)[NSEntityDescription insertNewObjectForEntityForName:@"MUSTHAFA" inManagedObjectContext:managedObjectContext];
[event setLastName:@"JOHN"];
[event setFirstName:@"JOSE "];
[event setLocation:@"IDUKKI "];
[event setAge:[NSNumber numberWithInt:25]];
NSError *error;
if (![managedObjectContext save:&error])
{
NSLog(@"Error..%@",error);
}
else
{
NSLog(@"Data added to MUSTHAFA ");
}
}
从核心数据中检索所有值,就像从 dbTable 中选择 *;
-(void)FetchRecordFromCoreData:(id)data1{
//NSLog(@"______ Fetch Core Data Implementaion");
MUSTHAFA *event = (MUSTHAFA *)[NSEntityDescription insertNewObjectForEntityForName:@"MUSTHAFA" inManagedObjectContext:managedObjectContext];
//USING event how can fetch all record from Data base;
}
USING 事件(MUSTAHFA 的实例)如何从数据库中获取所有记录?