Objective-C 跟 C++
Objective-C 內的member method C++有dd分別。C++內是用的實體的pointer去行member method, 但Objective-C用的機制是messaging, 所以在Objective-C內nil的pointer係可以call member method而唔會crash!
C++:
SomeClass * instance = null;
instance->SomeMethod();
CRASH @.@
Objective-C:
SomeClass * instance = nil;
[instance SomeMethod];
SAFE, but returns nil
^.^
沒有留言:
張貼留言