Objective C的方法和语法 [英] Objective C Methods and syntax
问题描述
我用Objective-C的工作时感到有点困惑。这部分特别混淆了我很多。
I am a bit confused when working with objective-c. This part in particular confuses me a lot.
什么是写作code这样的...
What is the purpose and/ or difference between writing code like this ...
object = [object method];
和
[object method];
学习Objective-C到现在为止,我一直认为我可以做这样的事情。
Learning objective-c up until now, I always assumed that I could do something like this..
说,我已经创造了这个..
say I had already created this..
NSString *object = [[NSString alloc]initWithFormat:@"%@"];
然后我可以做我想做的与像这样..
then I could do what I want with that like so..
[object applyAnyMethodHere];
但现在我看到这样的事情。
but now I'm seeing things like this ..
object = [object applyAnyMethodHere];
什么是这两者之间的区别?
What is the difference between these two?
推荐答案
第一个(对象= [对象的方法];
)的任何方法返回的分配。
The first one (object = [object method];
) is an assignment of whatever method returns.
第二个( [对象的方法];
)。只是调用该方法,而不注重其返回值(如果有的话)
The second one ([object method];
) is just calling the method without paying attention to its return value (if any).
第三(的NSString *对象= [[NSString的页头] initWithFormat:@@]
)声明变量并分配 initWithFormat
呼吁页头的方法的返回值
类方法。
The third (NSString *object = [[NSString alloc]initWithFormat:@"@"]
) declares variable and assigns the return value of the initWithFormat
method called on the return value of the alloc
class method.
这篇关于Objective C的方法和语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!