español data objective-c ios core-data nsmanagedobject nsmanagedobjectcontext

objective-c - español - core data swift 4



¿Cómo obtener todos los registros de CoreData Base utilizando NSManagedObjectSubClass? (2)

NSManagedObjectContext *context = //Get it from AppDelegate NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"MUSTHAFA"]; NSError *error = nil; NSArray *results = [context executeFetchRequest:request error:&error]; if (error != nil) { //Deal with failure } else { //Deal with success } [request release];

Estoy tratando de implementar CoreData en la aplicación ios , ahora quiero obtener todos los registros de la entidad 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

Agregar registros a datos básicos

-(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 "); } }

Recuperación de todos los valores de Core Data igual que select * from 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; }

UTILIZANDO el evento (Instancia de MUSTAHFA) ¿cómo se puede recuperar todo el registro de la base de datos?


AppDelegate *delegate = [UIApplication sharedApplication].delegate; NSManagedObjectContext *context =[delegate managedObjectContext]; NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Channels"]; NSError *error = nil; NSArray *results = [context executeFetchRequest:request error:&error]; ChannelDBArray=[[NSMutableArray alloc]init]; for (NSManagedObject *obj in results) { NSArray *keys = [[[obj entity] attributesByName] allKeys]; NSDictionary *dictionary = [obj dictionaryWithValuesForKeys:keys]; } if (error != nil) { //Deal with failure } else { //Deal with success }