“_”之间的区别是什么?和“__”在Objective-C? [英] What's the difference between "_" and "__" in Objective-C?
问题描述
我已经读过, _
(下划线)仅用于告诉变量/方法/类是仅供API使用,不应该被其他
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.
__
(双下划线)?
在此示例中 __ block BOOL found = NO;
。
From the Apple Docs about Block Objects.
此外,任何人都可以帮助我理解指针到指针的概念?
** var
我读了一些关于它的答案,但没有真正得到它。
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?
推荐答案
单下划线传统上用于私有API(方法,有时是ivars)。它们的主要目的是防止名称冲突。
Single underscore is traditionally used for private API (methods and sometimes ivars). Their main purpose is to prevent name collisions.
__ block
是新块API的关键字。
__block
is a keyword for the new blocks API. In general, double underscore keywords are for the compiler.
对于指针的指针, NSError
就是一个很好的例子:当一个方法想要返回一个新的 NSError
对象作为其参数(不是返回值)的一部分时,您需要一个指向 NSError *
,以便您可以分配它。有了一个简单的指针,你只能访问对象,但不能(重新)分配。
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.
这篇关于“_”之间的区别是什么?和“__”在Objective-C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!