Re: Need to find out why I get Cocoa error 256 . . . (more info)
Re: Need to find out why I get Cocoa error 256 . . . (more info)
- Subject: Re: Need to find out why I get Cocoa error 256 . . . (more info)
- From: "Michael A. Crawford" <email@hidden>
- Date: Mon, 13 Apr 2009 16:21:45 -0400
When I change the persistent-store type from SQLite to Binary, my code
works. I'm able to save the Managed Object Context. On the next run,
my fetch works because there is not data in the persistent store.
Anyone have any idea why the store type makes the difference?
/**
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the
application's store added to it.
*/
- (NSPersistentStoreCoordinator*)persistentStoreCoordinator
{
if ( nil == persistentStoreCoordinator )
{
#if 0
NSURL* storeUrl = [NSURL fileURLWithPath:[[self
applicationDocumentsDirectory]
stringByAppendingPathComponent:@"SpecialOrders.sqlite"]];
#else
NSURL* storeUrl = [NSURL fileURLWithPath:[[self
applicationDocumentsDirectory]
stringByAppendingPathComponent:@"SpecialOrders.bin"]];
#endif
NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator
alloc] initWithManagedObjectModel:[self managedObjectModel]];
#if 0
if ( ![persistentStoreCoordinator
addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl
options:nil error:&error] )
#else
if ( ![persistentStoreCoordinator
addPersistentStoreWithType:NSBinaryStoreType
configuration:nil URL:storeUrl
options:nil error:&error] )
#endif
{
// Handle error
NSLog(@"Error adding persistent store to coordinator");
}
}
return persistentStoreCoordinator;
}
#pragma mark -
#pragma mark AppController methods
- (void)viewDidLoad
{
[super viewDidLoad];
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem* addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
NSError *error;
if ( ![[self fetchedResultsController] performFetch:&error] )
{
// Handle the error...
NSLog(@"Failed to perform initial fetch for view");
}
//
// If the fetch resulted in no records, create and save instances
of each of
// the model objects.
//
NSArray* fetchedObjects = [[self fetchedResultsController]
fetchedObjects];
if ( (nil == fetchedObjects) || (0 == fetchedObjects.count) )
{
NSLog(@"Nothing returned from fetch; creating dummy objects");
Language* language = [NSEntityDescription
insertNewObjectForEntityForName:@"Language"
inManagedObjectContext:self.managedObjectContext];
language.name = @"English";
language.symbol = @"EN";
Publication* publication = [NSEntityDescription
insertNewObjectForEntityForName:@"Publication"
inManagedObjectContext:self.managedObjectContext];
publication.ID = [NSNumber numberWithInt:5334];
publication.languages = [NSSet setWithObject:language];
publication.name = @"Bible Teach";
publication.symbol = @"bh";
language.publications = [NSSet setWithObject:publication];
Publisher* publisher = [NSEntityDescription
insertNewObjectForEntityForName:@"Publisher"
inManagedObjectContext:self.managedObjectContext];
publisher.firstName = @"Michael";
publisher.lastName = @"Crawford";
Request* request = [NSEntityDescription
insertNewObjectForEntityForName:@"Request"
inManagedObjectContext:self.managedObjectContext];
request.language = language;
request.publication = publication;
request.publisher = publisher;
request.timeStamp = [NSDate date];
publisher.requests = [NSSet setWithObject:request];
publication.requests = [NSSet setWithObject:request];
Order* order = [NSEntityDescription
insertNewObjectForEntityForName:@"Order"
inManagedObjectContext:self.managedObjectContext];
order.ID = [NSNumber numberWithInt:1];
order.requests = [NSSet setWithObject:request];
order.timeStamp = [NSDate date];
request.order = order;
NSLog(@"language = %@", language);
NSLog(@"publication = %@", publication);
NSLog(@"publisher = %@", publisher);
NSLog(@"request = %@", request);
NSLog(@"order = %@", order);
NSError* error;
if ( ![[fetchedResultsController managedObjectContext]
save:&error] )
{
NSLog(@"Failed to save context with new data: %@", error);
}
[self.tableView reloadData];
}
}
-Michael
----------------------
There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies.
And the other way is to make it so complicated that there are no
obvious deficiencies.
-- C.A.R. Hoare
On Apr 13, 2009, at 10:25 AM, Michael A. Crawford wrote:
Where can I find detail on the following error code? Or, can
someone point me to information on how to effectively debug a
failure for a CoreData -[NSManagedObjectContext save] invocation?
2009-04-13 10:17:28.625 SpecialOrders[4923:20b] Failed to save
context with new data: Error Domain=NSCocoaErrorDomain Code=256
UserInfo=0xf4b150 "Operation could not be completed. (Cocoa error
256.)"
-Michael_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden