【发布时间】:2013-04-07 03:10:48
【问题描述】:
我只是在学习 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 上也搜索过,但找不到太多帮助。
【问题讨论】:
-
你使用的是什么编译器+运行时?
-
你需要 Clang。不要使用 GCC。并确保您安装了正确版本的运行时,当您不知道自己在做什么时,请使用 GNUstep-make 构建项目。
-
我只是在学习obj c。我正在使用从 gnustep.org/experience/Windows.html 下载的 GNUStep(有 3 个安装程序 - msys 系统、核心、开发)。
-
请建议如果我在 mac 上使用 Xcode 或者我需要使用其他东西,这会起作用吗?
-
我不知道 clang 能否在 Windows 上运行良好。尽管它在 x86 上与 FreeBSD 和 GNU/Linux 等其他一些操作系统确实可以正常工作。您所做的是使用过时的编译器 GCC 不支持的新语法。我会安装 Ubuntu 并检查此页面 wiki.gnustep.org/index.php/ObjC2_FAQ
标签: nsdictionary objective-c-blocks gnustep