Hi all,
2 questions if I may.
Part of the exercise is to show how KVC coding will use accessors **if** they are present.
To set this up, we write a new init method. ("fido" is an ivar of the class)
I am thinking this is incorrect, and should be this.
But...I am betting against Hillegas, so is there a reason why he omits setting the return from super to self?
Then, we write accessors in the standard way, but also add the declaration to the header file for the class, thus.
Now, again, why are we doing this, when Class AppController is a child of NSObject. The fact that KVC works, does this not assume that fido and setFido already conform to KVC and need not be declared. ( And in fact, the code compiles and runs without declaring these methods without any warnings or errors)
Thanks as usual.
2 questions if I may.
Part of the exercise is to show how KVC coding will use accessors **if** they are present.
To set this up, we write a new init method. ("fido" is an ivar of the class)
Code:
-(id) init
{
[super init];
[self setValue: [NSNumber numberWithInt: 5] forKey: @"fido"];
NSNumber *n = [ self valueForKey: @"fido"];
NSLog(@"Value for \"fido\": %@", n);
return self;
}
I am thinking this is incorrect, and should be this.
Code:
-(id) init
{
self = [super init];
if (self)
{
NSLog(@"Setting fido to \"5\"");
[self setValue: [NSNumber numberWithInt: 5] forKey: @"fido"];
NSNumber *n = [ self valueForKey: @"fido"];
NSLog(@"Value for \"fido\": %@", n);
}
return self;
}
But...I am betting against Hillegas, so is there a reason why he omits setting the return from super to self?
Then, we write accessors in the standard way, but also add the declaration to the header file for the class, thus.
Code:
-(int) fido;
-(void) setFido: (int) n;
Now, again, why are we doing this, when Class AppController is a child of NSObject. The fact that KVC works, does this not assume that fido and setFido already conform to KVC and need not be declared. ( And in fact, the code compiles and runs without declaring these methods without any warnings or errors)
Thanks as usual.