How to override a variadic method in Objective-C

青春壹個敷衍的年華 提交于 2019-12-23 11:54:12

问题


I'm trying to extend a class that has a variadic method such as:

- (void)someMethod:(id)arguments, ... ;

and in the subclass override it by calling the original method like:

- (void)someMethod:(id)arguments, ... {
    [super someMethod:arguments, ...];

    // override implementation
    ...
}

but this doesn't work. Anyone know how to work this? Thanks.


回答1:


similar to printf/vprintf, the base would declare:

- (void)someMethod:(id)arguments, ... ;

the subclass would implement:

- (void)vsomeMethod:(id)arguments vaList:(va_list)vaList;

then the base would just call vsomeMethod:vaList: in its implementation of someMethod:vaList:.



来源:https://stackoverflow.com/questions/9562361/how-to-override-a-variadic-method-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!