objective-c - 在oc里面点号和中括号发送消息的区别
PHP中文网
PHP中文网 2017-04-21 10:57:14
0
3
481

本来我以为在oc里面发送一个消息只能用中括号的

后来一个typo让我发现其实直接像c++那样用点号也是可以发送消息,只不过会多一个警告,内容看不太明白

很奇怪他说得并不是deprecated什么的,而是说这么用有副作用,不只看有谁能帮我解析一下这里说的副作用是什么意思

相关代码

// 申明
@property (weak, nonatomic) IBOutlet UITextField *textfield; 

// 运行代码
self.textfield.resignFirstResponder; //写成这样会出警告,但是能运行

[self.textfield resignFirstResponder]; // 按这样的标准写法就没事
PHP中文网
PHP中文网

认证0级讲师

reply all(3)
小葫芦

This line of warning is like this. It does not mean that there are any side effects if you do this, but it means that the getter is used to obtain the value, and sending resignFirstResponder is a side effect. It is not recommended to use the getter.
The .number is equal to the getter and setter methods on the properties of @synthesize

阿神

The literal translation is: the return value of the attribute is not used.
In other words: should
a =b.c;
It is not recommended to use it directly
b.c;
Unlike class methods, you can use methods like this:
o.method();

黄舟

I learned that the resignFirstResponder method is generally used to send messages.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template