gpt4 book ai didi

ios - Swift - pathForResource inDirectory 参数

转载 作者:可可西里 更新时间:2023-11-01 00:53:43 26 4
gpt4 key购买 nike

我正在制作一个非常简单的应用程序,它使用 UIWebView 来显示可以放大、平移等的 pdf map 。

但是,在为 pdf 创建目标 url 时,pathForResource 调用无法正常工作。这是我的代码:

var targetURL : NSURL = NSBundle.mainBundle().pathForResource(filename, ofType: type)

我在“文件名”之前的括号中收到错误消息,即 Missing argument for parameter 'inDirectory' in call。我尝试为此添加一个参数:

var targetURL : NSURL = NSBundle.mainBundle().pathForResource(filename, ofType: type, inDirectory: "Map")

我不知道要为 inDirectory 放什么,因为我不知道目录是什么 - 我将文件添加到我的项目中,它与我的 ViewController 位于同一文件夹中。快速文件。无论如何,这并不重要,因为我在同一个地方收到以下错误,Extra argument 'inDirectory in call

我该怎么办?

最佳答案

pathForResource() 不返回一个 NSURL 对象,而是一个 String?。相应地声明您的变量,它应该可以工作。

var targetURL : String? = NSBundle.mainBundle().pathForResource(filename, ofType: type)

或者,当然,如果您愿意 - 只需使用 URLForResource() 即可。

var targetURL : NSURL? = NSBundle.mainBundle().URLForResource(filename, withExtension: type)

关于ios - Swift - pathForResource inDirectory 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26060934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com