Objective-C 方法调用语法疑惑,求解答
PHP中文网
PHP中文网 2017-04-24 09:12:19
0
2
294

NSArray *arr = @[@"Helo", @"Word"];

NSLog(@"%d", (int) arr.count); // 1. 什么情况下这样调用方法?

NSUInteger count = [arr count]; // 2. 什么情况下这样调用? 似乎两者均可
NSLog(@"%lu", (unsigned long)count);

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
小葫芦

@testHs’ statement is not accurate.
Dot syntax is used to access attribute access methods (getters and setters), setter方法显然是要传入参数的。方式为object.propertyName = something
You can do everything [] that dot syntax can do (not necessarily vice versa), but dot syntax is more convenient.

阿神

Both are available.
When using [], you can pass parameters in, but when using ., you cannot pass parameters.

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