本帖最后由 一只小菜鸟 于 2014-4-27 22:52 编辑
- #import <Foundation/Foundation.h>
- #import "Person.h"
- int main(int argc, const char * argv[])
- {
- Person *p = [[Person alloc] init];
- [p test];
- p.test; //property access result unused - getters should not be used for side effect
- return 0;
- }
复制代码- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- - (void)test;
- @end
复制代码- #import "Person.h"
- @implementation Person
- -(void)test {
- NSLog(@"test success!");
- }
- @end
复制代码 点语法可以直接调用方法?
//只是有个警告property access result unused - getters should not be used for side effects
上个帖子的也没人答,一起放这里把
- NSDictionary *dict2 = @{@"k1": @"v1", @"k2": @"v2" };
- NSEnumerator *enumerator = [dict keyEnumerator];
- id key = nil;
- //这样是不会警告,
- while (key = [enumerator nextObject]) {
- //改成这样key = enumerator.nextObject 就会出现警告。赋值必须得圆括号
- //得改成while((key = enumerator.nextObject));if等同
- //我简单的测试了下,自己建了个类,用自己的get方法同样出现这个警告
-
- //另外,点语法不是get,和set方法么,enumerator.nextObject,[enumerator nextObject]返回值不同?
- //求科普,[enumerator nextObject],这为什么没警告,
- id value = [dict2 objectForKey:key];
- NSLog(@"%@", value);
复制代码
|