문제

In Xcode, if I start typing "[NSArray arrayWith" I get the following hint:

id arrayWithObjects:(id), ..., nil

As you can see, the terminator is explicit.

If I write a method taking variadic arguments by myself, I get this hint

id myMethod:(id), ...

(the terminator is not shown). How can I hint the terminator I want to use?

도움이 되었습니까?

해결책

Apply the

__attribute__((sentinel))

attribute to your variadic method, or alternatively, use the

NS_REQUIRES_NIL_TERMINATION

macro, which expands to the same. This way, the compiler will know that your variadic argument list needs to be 0-terminated.

- (void)foo:(id)arg1, ... NS_REQUIRES_NIL_TERMINATION
{
    va_list args;
    va_start(args, arg1);
    // ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top