I am developing an app that saves a URL using CoreData. I am defining NSManagedObjectContext, NSManagedObjectModel, NSPersistentStoreCoordinator in CoreDataRepository object class instead of AppDelegate. I am saving this URL using reference of CoreDataRepository. I am using the code below for getting CoreData
-(void)getcoredata
{
_coredatarep = [[CoreDataRepository alloc] init];
NSManagedObjectContext *context=[_coredatarep managedObjectContext];
NSFetchRequest *request=[[NSFetchRequest alloc] init];
NSEntityDescription *entity=[NSEntityDescription entityForName:@"UrlData" inManagedObjectContext:context];
[request setEntity:entity];
NSError *error;
NSArray *recordsDataArray=[context executeFetchRequest:request error:&error];
urlMutableArray = (NSMutableArray *)recordsDataArray;
for (int i=0; i<[urlMutableArray count]; i++)
{
urlString = [NSString stringWithFormat:@"%@", [urlMutableArray objectAtIndex:0]];
NSLog(@"urlString is %@",urlString);
_urlLabel.text=urlString;
}
}
In the output, label text shows as
<NSManagedObject: 0x9920620> (entity: UrlData; id: 0x991faf0 <x-coredata://A00EB59A-C480-4237-A749-8A40BF908655/UrlData/p1> ; data: <fault>)
Any idea why this is happening?
As I said in your other thread, it’s printing what you told it to print.
[urlMutableArray objectAtIndex:0]is aUrlDataobject and that’s its description. If you want a string that’s stored inside theUrlData, you need to ask it for one of its properties…whatever you’ve defined them to be in your data model.