dontWatchMyProfile
dontWatchMyProfile

Reputation: 46360

Does the type in this KVC validation method matter?

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?

Upvotes: 0

Views: 146

Answers (1)

Marcus S. Zarra
Marcus S. Zarra

Reputation: 46718

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.

Upvotes: 1

Related Questions