On Oct 18, 2010, at 4:42 PM, Trygve Inda wrote:

> So is "weapons" only defined in IB under the Array binding's model key path?

Yep, and Cocoa can automatically generate an array from it for 
NSArrayController.

#import <Foundation/Foundation.h>

@interface Combatant : NSObject {
@private
        id weapon1;
        id weapon2;
        id weapon3;
}

- (NSUInteger)countOfWeapons;
- (id)objectInWeaponsAtIndex:(NSUInteger)index;

@end

@implementation Combatant

- (id)init {
        self = [super init];
        
        if(self) {
                weapon1 = [@"Nerf gun" copy];
                weapon2 = [@"Super Soaker" copy];
                weapon3 = [@"Rubber Band" copy];
        }
        
        return self;
}

- (void)dealloc {
        [weapon1 release];
        [weapon2 release];
        [weapon3 release];
        
        [super dealloc];
}

- (NSUInteger)countOfWeapons {
        return 3;
}

- (id)objectInWeaponsAtIndex:(NSUInteger)index {
        switch (index) {
                case 0:
                        return weapon1;
                case 1:
                        return weapon2;
                case 2:
                        return weapon3;
                default:
                        return nil;
        }
}

@end

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        Combatant *combatant = [[Combatant alloc] init];
        
        NSLog(@"%@", [combatant valueForKey:@"weapons"]);
        
        [combatant release];

    [pool drain];
    return 0;
}

-----------------------

Running this produces the following output:

2010-10-18 16:52:26.336 proptest[58175:a0f] (
    "Nerf gun",
    "Super Soaker",
    "Rubber Band”
)

Charles_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to