代码如下:
类的声明如下
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property int age;
@end
main.m 如下
#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
Person *p = [Person new];
id d = [Person new];
[d setAge:100];
// d.age = 100; // 报错
NSLog(@"test %d",[d age]);
//NSLog(@"test %d",d.age);
NSLog(@"test %d",p.age);
return 0;
}
其中 /d.age = 100; 和 NSLog(@"test %d",d.age); 这两行报如下:
Property 'age' not found on object of type '_strong id'
求大神解答, id 不能使用点语法吗? |
|