开发者

What's the difference between "_" and "__" in Objective-C?

I've read that _ (underscore) is only used to tell that the variable/method/class is for the API use only and should not be used by other programmers.

What about __ (double underscore)?

In this example __block BOOL foun开发者_如何转开发d = NO;

From the Apple Docs about Block Objects.

Also, can anyone help me understand the concept of pointer-to-pointers? **var I've read some answers about it but didn't really get it. When and how should I use it?


Single underscore is traditionally used for private API (methods and sometimes ivars). Their main purpose is to prevent name collisions.

__block is a keyword for the new blocks API. In general, double underscore keywords are for the compiler.

For pointers to pointers the NSError is a good example: When a method wants to return a new NSError object as part of its parameters (not return value), you need a pointer to a variable of type NSError *, so that you can assign it. With a simple pointer you could only access the object, but not (re-)assign it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜