开发者

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜