Swift調用OC之文件操作-NSBundle

//***************************************************

//

//      >>>>>>>Swift調用OC之文件操作-NSBundle<<<<<<<

//

// NSBundle內含有:

//    -- info.plist:這是必須要有的文件,用來配置應用的基本參數信息

//    -- 可執行文件

//    -- 資源文件:如圖像、圖標、音頻文件等

// 對於AppmainBundle通常指向xxx.app/這個根目錄

//

//

//***************************************************

 

import Foundation

 

let mainBundle = NSBundle.mainBundle()  //NSBundle</Users/../Library/../data/Containers/Bundle/Application/../TEST1.app>

 

let bundleURL = mainBundle.bundleURL    //file:///Users/.../Library/Developer/../Devices/../data/Containers/Bundle/Application/../TEST1.app/

 

let bundlePath = mainBundle.bundlePath  //Users/../Library/Developer/../Devices/../data/Containers/Bundle/Application/../TEST1.app

 

 

 

//----- 獲得bundle目錄下的文件 -----//

let FileURL = mainBundle.URLForResource("Personal", withExtension: "jpg"//就是前面bundleURL+"/"+Personal.jpg

let FilePath= mainBundle.pathForResource("Personal", ofType: "jpg")        //就是前面bundlePath+"/"+Personal.jpg

 

//----- 獲得bundle信息 -----//

let identifier = mainBundle.bundleIdentifier       //Optional("EvaZis.TEST1")

let info = mainBundle.infoDictionary               //獲得info.plist配置項詞典對象實例

let bundleId:AnyObject? = mainBundle.objectForInfoDictionaryKey("CFBundleName") // 獲得應用程序的Bundle:Optional(TEST1)

println("info=\(info)")

println("bundleId=\(bundleId)")


發佈了62 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章