//SomeObject.h
#import <Foundation/Foundation.h>
@interface SomeObject : NSObject {
}
@property NSInteger aProperty;
@end
//main.m
#import <Foundation/Foundation.h>
#import "SomeObject.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:[[[SomeObject alloc] init] autorelease] forKey:@"key1"];
[dictionary setObject:[[[SomeObject alloc] init] autorelease] forKey:@"key2"];
[dictionary objectForKey:@"key1"].aProperty = 5; //Error HERE
[dictionary release];
[pool drain];
return 0;
}
但在该行的XCode给我这些错误:无法访问返回对象的属性?
error: Semantic Issue: Member reference type 'struct objc_object *' is a pointer; maybe you meant to use '->'?
error: Semantic Issue: No member named 'aProperty' in 'struct objc_object'
我不能访问返回的对象的属性? (我的意思是,没有直接调用setter方法)
煤焦与指针“*”?我是noob,但我从来没有看到带有星号的字符,就像你做的那样“char * argv []” – doNotCheckMyBlog
这就像编写char argv [] []或char ** argv ...这是一个二元数组,每个标准C main接收命令行参数应该有这样的参数列表。 –