//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接收命令行參數應該有這樣的參數列表。 –