【发布时间】:2023-03-17 08:38:01
【问题描述】:
我正在开发一个使用 JSContext 来实现某些功能的 Mac 应用程序。
它使用这样的调用(其中ctx 是JSContext):
let result: JSValue? = ctx.evaluateScript("someFunction")?.call(withArguments: [someArg1!, someArg2])
在someFunction 脚本中,我们需要解析一个目录并确定它是否存在于文件系统中。据我所知,Apple 的 JavaScriptCore API 没有文件系统访问权限。
有什么方法可以让我在 swift 中拥有这样的功能:
public static func isAppDirectory(_ path: String) -> Bool {
var isDirectory = ObjCBool(true)
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
return exists && isDirectory.boolValue
}
并将一些自定义函数指针传递给 JSContext 以调用该函数?
【问题讨论】:
标签: swift macos cocoa javascriptcore jscontext