1 min read

Switch "resource" to "resource_bundle"

Today I tried to switch attribute resource to resource_bundle for a private pod.

//s.ios.resource = ['MyPrivatePod/Assets/**/*.{xib,storyboard,xcassets}', 'MyPrivatePod/Classes/**/*.{xib,storyboard,xcassets}']

s.ios.resource_bundle = {
  'Resources' => ['MyPrivatePod/Assets/**/*.{xib,storyboard,xcassets}', 'MyPrivatePod/Classes/**/*.{xib,storyboard,xcassets}']
}

After the change I built and ran, I got a crash:

Unknown class _TtC9Resources21ProductListHeaderView in Interface Builder file.
Could not cast value of type 'UICollectionReusableView' (0x108c9d9c8) to 'MyPrivatePod.ProductListHeaderView' (0x104972798).

It turns out the nib was assigned to Resources target which contains the files and iOS can't find anything about my custom class. Change the module name to Resources fixed the issue.

What's weird is if I use MyPrivatePod as the resource_bundle name, this issue is gone. So it seems the best practice is to just use the pod name as the name of your resource_bundle and avoid all the hassle.