Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What cause EXC_BAD_ACCESS?



Hi guys,

I'm sorry I'm a newbie of Cocoa so that I don't know if I can show you appropriate situation, but I'll try.

An EXC_BAD_ACCESS error comes only after my app reads my custom format type of data and reads document nib file.

1. When new document is selected, no problem.
2. When open document is selected and the app reads one of three formats which Core Data supports, no problem.
3. Only after reading custom formatted file and after windowControllerDidLoadNib gets called, EXC_BAD_ACCESS comes.
The windowControllerDidLoadNib method calls [super windowControllerDidLoadNib] and detects how each attribute of managedObjects
has been set.


It looks fine that the custom formatted data is read, and the objects created and initialized with the data seem to be fine.
Because the value of each attribute of managedObjects was what I expected.



Entity: Employ name(attribute) department(one relationship)

Entity: Department
  dept_name(attribute)
  employees(many relationship)

@interface DepartmentMO : NSManagedObject
{
}

- (int) convertCTypeOfDataToManagedObject:(NSData*)data
			         position:(unsigned long*)position
			      withVersion:(int)version;

This method reads a custom type of data and set all attributes of entity "Department" using setValue:forKey method.
In this method, it creates EmployeeMO by using insertNewObjectForEntityForName: inManagedObjectContext: and
obtains employees relationship using mutableSetValueForKey: and add the created object to the attribute using addObject.
Of cause department attribute of the EmployeeMO object set this department object (self) using setValue:forKey:.


@ interface EmployMO : NSManagedObject
{
}

- (int) convertCTypeOfDataToManagedObject:(NSData*)data
			         position:(unsigned long*)position
			      withVersion:(int)version;

This method reads a custom type of data and set all attributes of this entity using setValue:forKey method.


The following steps are in one function.

DepartmentMO* department = nil;
for (i = 0 ; i < counter; ++i )
{
department = (DepartmentMO*)[NSEntityDescription insertNewObjectForEntityForName:@"Department"
inManagedObjectContext:context];


(void)[department convertCTypeOfDataToManagedObject:data position:&pos withVersion:version];

 [context processPendingChanges];
}

In the convertCTypeOfDataToManagedObject:position:withVersion: of DepartmentMO

NSMutableSet * inObjects = [self mutableSetValueForKey:@"employees"];
for (i = 0; i < numOfHistory; ++i)
{
employee = (EmployMO*)[NSEntityDescription insertNewObjectForEntityForName:@"Employ"
inManagedObjectContext:[self managedObjectContext]];


(void)[employee convertCDataToManagedObject:data position:position withVersion:version ];

[employee setValue:self forKey:@"department"];

[inObjects addObject:employee];
}



Thank you for reading this poor explanation. I hope what mentioned above is understandable.


Norio Ota

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.