在objective-c中覆盖可变参数方法 [英] Overriding a variadic method in objective-c

查看:66
本文介绍了在objective-c中覆盖可变参数方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在objective-c中子类化时,如何在可变参数方法的情况下将调用转发到超类.我应该用什么来代替???下面发送我得到的所有对象?

When subclassing in objective-c, how can I forward a call to the superclass in the case of a variadic method. By what should I replace the ??? below to send all the objects I got?

- (void) appendObjects:(id) firstObject, ...
{
   [super appendObjects: ???];
}

推荐答案

你不能.要安全地传递所有可变参数,您需要一个方法来接受 va_list.

You can't. To safely pass all the variadic arguments, you need a method to accept a va_list.

超级,

-(void)appendObjectsWithArguments:(va_list)vl {
  ...
}

-(void)appendObject:(id)firstObject, ...
  va_list vl;
  va_start(vl, firstObject);
  [self appendObjectsWithArguments:vl];
  va_end(vl);
}

并在覆盖子类中的方法时使用 [super appendObjectsWithArguments:vl].

And use [super appendObjectsWithArguments:vl] when you override the method in the subclass.

这篇关于在objective-c中覆盖可变参数方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆