Core Data: Unable to store a NSData object into an entity's binary property.
Core Data: Unable to store a NSData object into an entity's binary property.
- Subject: Core Data: Unable to store a NSData object into an entity's binary property.
- From: "Frederick C. Lee" <email@hidden>
- Date: Fri, 6 Jan 2006 14:05:57 -0800
I'm really stuck!
Why can't I populate a binary attribute of an Entity Object?
Persistent Storage Type: NSXMLStoreType
[Region] -->> [Map]
imageData (binary)
I've been trying to stuff a binary property with a NSData object and
see if the persistent storage accepts it.
Apparently it doesn't.
================================
1) Create the receiving entity object 'Map' with back-link to its
parent 'Region':
NSMutableSet *regionMaps = [region
mutableSetValueForKey:@"map"]; // Region:Maps --> 1:many
NSManagedObject *map = [[NSManagedObject alloc] init];
map = (NSManagedObject *)[NSEntityDescription
insertNewObjectForEntityForName:@"Map"
inManagedObjectContext:managedObjectContext];
[map setValue:[NSString stringWithFormat:@"%@ Map",inRegion]
forKey:@"name"];
NSData *myData = [NSData dataWithContentsOfFile:@"/Users/Ric/Library/
Application Support/Eccron/Maps/tiff/Europe1.tif"];
if (myData)
[map setValue:myData forKey:@"imageData"];
[regionMaps addObject:map];
[map release];
================================
2) I have the Data for entry:
(gdb) print (int) [myData length]
$1 = 130236
================================
3) Here's a last-minute check of the MOC before SAVING to Storage:
(gdb) po [managedObjectContext insertedObjects]
<NSCFSet: 0x482d0b0> (<NSManagedObject: 0x482ae90> (entity: Map; id:
0x48269f0 <x-coredata:///Map/t43DB2DD5-3CEC-4AF0-9401-6A2471563D44> ;
data: {
city = nil;
country = nil;
image = nil;
imageData = <4d4d002a 00000008 001400fe 00040000 00010000
00000100 00030000 000102a3 00000101 00030000 00010203 00000102 0003>;
memo = nil;
name = "Europe Map";
region = 0x34d2e0 <x-coredata://
2CDD4E18-17BF-4936-9CE7-221131509293/Region/p103>;
subregion = nil;
}))
=================================
4) After the Save (without errors), I fetch the data and found NO
IMAGE, only the name (string):
NSSet *fetchedSetName = [[NSSet alloc] initWithSet:[fetchedObject
valueForKeyPath:@"map.name"]];
NSSet *fetchedSetImage = [[NSSet alloc] initWithSet:[fetchedObject
valueForKeyPath:@"map.imageData"]];
(gdb) po fetchedSetName
<NSCFSet: 0x481ef50> (Europe Map)
(gdb) po fetchedSetImage
<NSCFSet: 0x480d0c0> ()
Can anyone explain why a NSData object doesn't get stored in a entity
binary attribute?
Remedy?
Ric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden