我正在制作一个非常简单的应用程序,它使用UIWebView来显示可以放大、平移等的pdfmap。但是,在为pdf创建目标url时,pathForResource调用无法正常工作。这是我的代码:vartargetURL:NSURL=NSBundle.mainBundle().pathForResource(filename,ofType:type)我在“文件名”之前的括号中收到错误消息,即Missingargumentforparameter'inDirectory'incall。我尝试为此添加一个参数:vartargetURL:NSURL=NSBundle.mainBundle().p
在我的应用程序中,我有很多图片分为几类(以下是项目和我的硬盘中的应用程序树):ApplicationName-Resources--Thumbs--Images--Buttons--Default.png在thumbs文件夹中我有很多.png文件。问题是我想知道这个文件夹中有多少这些文件。我输入这样的命令:NSArray*namesArray=[[NSBundlemainBundle]pathsForResourcesOfType:@".png"inDirectory:@"Resources/Thumbs"];而且它没有在bundle中找到任何文件。当我使用inDirectory:@"
尽量不要笑或哭——我在20年后才重新开始编码......我花了4个多小时查看引用资料并尝试使用代码片段来获取Bundle.main.path打开我的文本文件,这样我就可以读取我的应用程序的数据(我的下一步是适本地解析它)。ifletfilepath=Bundle.main.path(forResource:"newTest",ofType:"txt"){do{letcontents=tryString(contentsOfFile:filepath)print(contents)}catch{print("Contentscouldnotbeloaded.")}}else{print(
我在名为TextFiles的文件夹中添加了一个文件paylines.txt,该文件夹位于Xcode中我的iOS项目的Resources文件夹中。这是我用来访问文件的代码:NSString*filePath=[[NSBundlemainBundle]pathForResource:@"paylines"ofType:@"txt"inDirectory:@"TextFiles"];NSLog(@"\n\nthestring%@",filePath);代码打印:2011-06-0714:47:16.251slots2[708:207]thestring(null)
我在名为TextFiles的文件夹中添加了一个文件paylines.txt,该文件夹位于Xcode中我的iOS项目的Resources文件夹中。这是我用来访问文件的代码:NSString*filePath=[[NSBundlemainBundle]pathForResource:@"paylines"ofType:@"txt"inDirectory:@"TextFiles"];NSLog(@"\n\nthestring%@",filePath);代码打印:2011-06-0714:47:16.251slots2[708:207]thestring(null)