• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
What cause EXC_BAD_ACCESS?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What cause EXC_BAD_ACCESS?


  • Subject: What cause EXC_BAD_ACCESS?
  • From: Norio Ota <email@hidden>
  • Date: Sun, 30 Sep 2007 23:26:06 +0900

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: What cause EXC_BAD_ACCESS?
      • From: Uli Kusterer <email@hidden>
    • Re: What cause EXC_BAD_ACCESS?
      • From: Fritz Anderson <email@hidden>
    • Re: What cause EXC_BAD_ACCESS?
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Build cocoa framework issue
  • Next by Date: Programatically bind NSArrayController to NSManagedObjectContext?
  • Previous by thread: Re: Build cocoa framework issue
  • Next by thread: Re: What cause EXC_BAD_ACCESS?
  • Index(es):
    • Date
    • Thread