2013-12-11 170 views
0

继答案我发现这里:https://stackoverflow.com/a/18121292/1701170,我有以下代码:如何正确声明和使用NSDictionary?

bool accessibilityEnabled = false; 

// Check and make sure assistive devices is enabled. 
if (AXIsProcessTrustedWithOptions != NULL) { 
    // 10.9 and later 
    NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES}; 
    accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); 
} else { 
    // 10.8 and older 
    if (AXAPIEnabled() == true) { 
     accessibilityEnabled = true; 
    } 
} 

if (accessibilityEnabled) { 
    // do something 
} 

我得到的错误如下:

[apply] error: use of undeclared identifier 'NSDictionary'; did you mean 'UseDictionary'? 
[apply]   NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES}; 
[apply]   ^~~~~~~~~~~~ 
[apply]   UseDictionary 

我一定要导入的NSDictionary?是

在文件顶部的进口如下:

#include <pthread.h> 
#include <sys/time.h> 

#include <ApplicationServices/ApplicationServices.h> 

#include "NativeErrors.h" 
#include "NativeGlobals.h" 
#include "NativeHelpers.h" 
#include "NativeThread.h" 
#include "NativeToJava.h" 
#include "OSXInputHelpers.h" 

这是我第一次看的Objective-C。

+1

你创造什么模板从这个项目?你链接了基金会吗?它是否正确导入? – DrummerB

+0

另外,不要把标签在你的职称,多亏 – DrummerB

+0

这是https://code.google.com/p/jnativehook/我在看的src /本地/ OSX/NativeThread.c,围绕线665个 – jononomo

回答

3

你的链接项目看起来像一个普通的C项目给我。 NSDictionary是一个Objective-C类,也是Apple基础框架的一部分。你必须链接Foundation.framework并确保它已经在源代码中导入。如果您只是在尝试,最好的办法可能是使用命令行工具(基础类型)模板在Xcode中创建一个新项目。

+0

谢谢。我可能在我的头上。我挂不会在OS X 10.9和我请编译该项目正在试图把一个简单的补丁,但我可能不会了解情况不够好。 – jononomo