Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active August 15, 2016 08:05
Show Gist options
  • Save KentarouKanno/148dd5bb7cdf12a2ec49 to your computer and use it in GitHub Desktop.
Save KentarouKanno/148dd5bb7cdf12a2ec49 to your computer and use it in GitHub Desktop.
NSBundle

NSBundle

★ NSBundleを取得する

let bundle = NSBundle.mainBundle()

★ info.plistからkeyを指定して値を取得する

let value: String = NSBundle.mainBundle().objectForInfoDictionaryKey("key") as! String

★ アプリバージョンを取得する

let version: String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String

★ ビルドバージョンを取得する

let build: String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion") as! String

★ Bundle Identifierを取得する

let bundleID = NSBundle.mainBundle().bundleIdentifier

★ ファイル名と形式を指定してPathを取得する

let path = NSBundle.mainBundle().pathForResource("sample", ofType: "txt")

★ Bundleのcsvファイルを読み込んでNSDataに変換する

let csvFile = NSBundle.mainBundle().pathForResource("data", ofType: "csv") 
let csvData = NSData(contentsOfFile: csvFile!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment