iPhone: can you tell me the difference b/t (NSObject *)obj&(NSObject *obj)
Can you tell开发者_运维百科 me what the difference is between
-(NSObject *)obj
and -(NSObject *obj)
?
-(NSObject *)obj
is the signature of an instance method called obj
that returns a pointer to an NSObject
.
-(NSObject *obj)
is nonsense.
(type)obj tells the code that you have an object "obj" and it is of type "type"
(type *)obj tells the code that you have a pointer to an object "obj" and it is of type "type"
Examples:
(int)n means I'm giving you an integer called n (float)n means I'm giving you a float called n
(NSObject *)obj means I'm giving you a pointer to an NSObject called obj
Non-Examples:
(int n) or (float n) or (NSObject *obj) are all nonsense
The first is a cast (NSObject *)obj whilst the second is a (NSObject *obj) dispensable use of brackets
精彩评论