LoginSignup
13
13

More than 5 years have passed since last update.

CocoaPodsで配布するライブラリにStoryboardを含めたい

Posted at

storyboardxibを同梱したかったのでやってみた。

と言っても、podspecにちょっと書き足してあげるだけ。

変更部分

podspecに、resource_bundlesを追記すればいい。

xxx.podspec
s.resource_bundles = {
  'バンドル名' => ['パス']
}

という感じ。

xxx.podspec
s.resource_bundles = {
  'ABC' => ['Assets/*.storyboard']
}

とか書けば、

ABC.bundleAssets配下の全ストーリーボードを入れられる。

呼び出し方

let path = NSBundle.mainBundle().pathForResource("ABC", ofType: "bundle")!
let bundle = NSBundle(path: path)
let storyboard = UIStoryboard(name: "NAME", bundle: bundle)

こんな感じで、bundleからストーリーボードを取り出せる。

xibや画像も基本的にはこのbundleを渡せば取得できる。

実際のpodspec

が追加してみたもの。

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13