views:

16

answers:

1

For example, in the docs a KVC-style validation method is implemented like this:

-(BOOL)validateAge:(id *)ioValue error:(NSError **)outError

They used id* as the type for ioValue. Since that's not part of the method signature, I wonder if it would hurt to do something like:

-(BOOL)validateAge:(NSNumber *)ioValue error:(NSError **)outError

Is this still fine with KVC?

+1  A: 

That would not work because they are not the same. id* would be closer to NSNumber** as the method accepts a pointer to a pointer. So your method would look like:

-(void)validateAge:(NSNumber**)ioValue error:(NSError**)outError

But there is NO point in doing that. id will work perfectly fine for everything that you need to do and if you change it and then adjust that attribute later you can and would introduce a subtle error into your application.

Short answer, yes you can change the input parameter type; but you really shouldn't.

Marcus S. Zarra