簡體   English   中英

在iOS應用程序的Xcode項目中引用目錄

[英]Referencing directories within an Xcode project for an iOS app

我需要能夠引用xCode項目內部目錄中的特定文件。 到目前為止,我有以下代碼:

let files = NSBundle.mainBundle().pathForResource("sampleFile", ofType: "csv")
var contents = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)!

它可以打開一個文件,但是我希望能夠打開一個存儲在主捆綁包中一個或兩個目錄中的文件。

有人知道怎么做這個嗎?

NSBundle有一種方法可以為單個文件指定目錄

  let file = NSBundle.mainBundle().pathForResource("sampleFile", ofType: "png", inDirectory:"Images")

或用於相同類型的多個文件

  let files = NSBundle.mainBundle().pathForResourcesOfType("png", inDirectory:"Images")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM