Not exactly.  Sorry I've done such a poor job describing what I'm after.

I've got an entity named Building (and also entities named Floor and Room). Each of these entities has an index attribute, which is an int16 type. All three entities inherit the index attribute and others from a common parent, which I'm calling IndexedObject. The UI has tables for each entity and '+' and '-' buttons to add and remove entities from the table and drag-and-drop to reorder the entities.

The '+' button is linked to the NSArrayController subclass' add: method, which automatically invokes insertNewObjectForEntityForName: inManagedObjectContext:. I've been using:

- (void)addObject:(Building *)object {
        [super addObject:object];
object.index = [NSNumber numberWithInt:[[self arrangedObjects] indexOfObject:object]];
        NSLog(@"Added %@", [object description]);
}

to override NSArrayController's standard implementation and assign an index to the newly-created object, based on its index within the underlying array. The problem is the type for the argument in the method declaration. With the standard method signature:

- (void)addObject:(id)object

the runtime doesn't have a specific entity to look to for a definition, so it doesn't know that I really want to be adding a Building entity, which does have an index attribute, and it throws an error. If I change the method declaration to:

- (void)addObject:(Building *)object

it knows that the Building entity has an index attribute, so the error goes away. But, that means that I need to create separate NSArrayController subclasses to control the arrays of the Floor and Room entities. I'm hoping to find a method declaration that can look to the entity type of the objects that the array controller is controlling (as set in IB), so that I can use the same subclass for the Building, Floor and Room arrays.

Having separate NSArrayController subclasses for Floor and Room isn't the end of the world, but if there's a cleaner way to do this, I'd like to learn about it.

Thanks for all of your help.

Brad


On Jul 18, 2009, at 12:24 PM, Quincey Morris wrote:

On Jul 18, 2009, at 10:36, Brad Gibbs wrote:

Can I use that to indicate the type for the argument to the method?

On Jul 18, 2009, at 9:45 AM, Quincey Morris wrote:

Perhaps NSSClassFromString ([[self entityName] managedObjectClassName])?

Sorry, I took your example too literally, and gave you the expression for the class name (apart from the typo). For insertNewObjectForEntityForName:inManagedObjectContext: you'd just need the entity name:

insertNewObjectForEntityForName: [self entityName] inManagedObjectContext: [self managedObjectContext]

Is that what you wanted?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/bradgibbs%40mac.com

This email sent to bradgi...@mac.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to