使用 NSOpenPanel 时出现大量错误

Getting loads of error when using NSOpenPanel

本文关键字:错误 NSOpenPanel 使用      更新时间:2023-10-16

我在网上找到了这段代码,它应该在C++中打开一个打开的对话框。但是我收到了很多错误。这是代码:

#import <Cocoa/Cocoa.h>
#include <string>
std::string* path() {
    NSOpenPanel *op = [NSOpenPanel openPanel];
    if ([op runModal] == NSOKButton) {
        NSURL *nsurl = [[op URLs] objectAtIndex:0];
            std::string([[nsurl path] UTF8String]);
    }
    //Here i do stuff with the string.
    return something;
}

以下是我在 Xcode 中遇到的错误列表:http://gyazo.com/5b2b5da1d5eca9dd9d6f53eec438850e

谢谢。

您需要确保您的项目在所需的框架中链接。

在构建目标的设置下,在"

常规"选项卡下,滚动到底部并找到"链接的框架和库"部分。您应该会看到Cocoa.framework列出。如果没有,请单击底部的加号,在弹出对话框中搜索"可可",然后添加Cocoa.framework