search

Home  >  Q&A  >  body text

Objective-C 方法调用语法疑惑,求解答

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

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

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

PHP中文网PHP中文网2892 days ago370

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-24 09:14:19

    @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.

    reply
    0
  • 阿神

    阿神2017-04-24 09:14:19

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

    reply
    0
  • Cancelreply