我只是在学习 obj c。我正在使用从 gnustep.org/experience/Windows.html 下载的 GNUStep(有 3 个安装程序 - msys 系统、核心、开发)。
运行以下代码:
#import <Foundation/Foundation.h>
int main (int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary *m_Dict =
[NSDictionary dictionaryWithObjectsAndKeys:
@"ABC", @"One",
@"DEF", @"Two",
@"GHI", @"Three",
nil ];
// Print all key-value pairs from the dictionary
[m_Dict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
NSLog(@"%@ => %@", key, obj);
}];
[pool drain];
return 0;
}
显示错误:
$ gcc -o c c.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Li
``braries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
c.m: In function 'main':
c.m:16:44: error: expected expression before '^' token
c.m:18:1: warning: 'NSDictionary' may not respond to '-enumerateKeysAndObjectsUs
ingBlock:' [enabled by default]
c.m:18:1: warning: (Messages without a matching method signature [enabled by def
ault]
c.m:18:1: warning: will be assumed to return 'id' and accept [enabled by default
]
c.m:18:1: warning: '...' as arguments.) [enabled by default]c
请提出我做错了什么。在 Stackoverflow 上也搜索过,但找不到太多帮助。