开发者

Method parameter that can take an object or a nil?

How do I spell a method whose argument can either be an object of a certain type, or nil? You see those all 开发者_如何学Cthe time in framework classes, but I've just encountered my first instance where it would be useful to create one.


You can always pass nil instead of an object, there's nothing special you need to specify.


- (void) myMethod:(Parameter *)aParameter {
  if (aParameter == nil) {
    ...
  } else {
    ...
  }
}

Elsewhere:

[anObject myMethod:foo];

Or:

[anObject myMethod:nil];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜