In observeValueForKeyPath:ofObject:change:context:
- why do the docs use NULL
instead of nil
when not specifying a context pointer?
相关问题
- CALayer - backgroundColor flipped?
- What means in Dart static type and why it differs
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Notice: Undefined property - how do I avoid that m
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
They're technically the same thing (0), but nil is usually used for an Objective-C object type, while NULL is used for c-style pointers (void *).
nil
should only be used in place of anid
, what we Java and C++ programmers would think of as a pointer to an object. UseNULL
for non-object pointers.Look at the declaration of that method:
Context is a
void *
(ie a C-style pointer), so you'd definitely useNULL
(which is sometimes declared as(void *)0
) rather thannil
(which is of typeid
).They're technically the same thing and differ only in style:
nil
is what to use for theid
type (and pointers to objects).NULL
is what you use forvoid *
.0
.I typically use the variant that matches the language where the type is declared.
NULL
is theC equivalent
ofnil
, a pointer to nothing;where
nil is zero typed as id
,NULL is zero typed as void*
.One important point you can’t send a message to NULL. So it is preferred to use nil in objective-C at many places.
They almost are the same thing except,
nil
is used in an Objective-C style. whereNULL
is for C type pointers and is typdef'ed to(void *)
.