C.Johns
C.Johns

Reputation: 10245

how to read NSData from coredata

I have set up coredata in my application which I am reading a NSData object into.. I have check to make sure all is fine and that the values are there, which they are and now I would like to pull that nsdata out and pass it to a method in my class.. But I am not sure how to read something like this from coredata..

The example I have seen of reading values from coredata is from the template code XCode generates.. but this is for an objectAtIndexPath:indexPath value... as shown below..

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
}

So I am hoping there is a way just to pull all of the NSData out of the attribute.. because thats all I have is just a blob of data that I parse myself.

any help would be greatly appreciated.

Update:

Okay so this is now how I am reading the data from my coredata store thanks to the great tutorial listed below.

 NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
                    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
                    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Manz" inManagedObjectContext:context];
                    [fetchRequest setEntity:entity];
                    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:nil];
                    for (NSManagedObject *info in fetchedObjects) {
                        [self startTheParsingProcess:[info valueForKey:@"masters"]]; //Send to a method if you like
//                        NSLog(@"content od coredata %@", [info valueForKey:@"masters"]); // Or log it to see whats in your coredata
                    }

Upvotes: 1

Views: 1294

Answers (1)

borrrden
borrrden

Reputation: 33421

Core Data supports NSData properties. Just add one to your model and you will be able to save and load it via the NSFetchedResult class. If you don't know what that means or how to do that, then I suggest a Core Data primer such as this one

Upvotes: 2

Related Questions