Example.app ├── LKPostingQueueManager.framework │ ├── Info.plist │ ├── LKPostingQueueManager │ └── Resources.bundle ←ここにくる(以前はもっと上の階層)
プログラムでこれを参照するにはメインバンドル配下では見つからない。
let path = NSBundle.mainBundle().pathForResource("Resource", ofType: "bundle")! → ここで nilでクラッシュ
let bundle = NSBundle(path: path)最初にフレームワークのバンドル(クラスが含まれるバンドル)を取って、そこから引き出すのがポイント。
let frameworkBundle = NSBundle(forClass: LKPostingQueueManager.self)
let path = frameworkBundle.pathForResource("Resources", ofType: "bundle")!
let bundle = NSBundle(path: path)関連
Resource Bundle の作り方と CocoaPodsでの配布※上記はフレームワーク化する前の話。フレークワーク化するとこんな面倒は入らず設定だけで済む。
s.resource_bundles = {
'Resources' => ['Pod/Assets/*']
}みたいな。



Responses
Leave a Response