Add a Xib File to a Swift Package

Add a xib file to a Swift Package

Currently Swift packages only support source code so you can't add a xib file to the package. Read the What's Missing? section in the following article:

Creating Swift Packages in Xcode

UPDATE

Xcode 12 allows you to add files that are not source code files to Swift packages. I have not created a Swift package so I cannot provide detailed instructions on how to add a xib file to a Swift package. But as @ffritz mentioned in a comment to this answer, Apple's documentation has an article on bundling resources in Swift packages.

Bundling Resources with a Swift Package

Package XIB in Swift framework for distribution?

You can load your .xib file from your framework like this :

UINib(nibName: "MyXib", bundle: NSBundle(identifier: "bundleName")

or if you know the name of a class in the framework

UINib(nibName: "MyXib", bundle: NSBundle(forClass: MyClass.self)

Framework iOS-XIB can't load NIB in package

I found a solution to this problem,
push the xib file to the resource folder

spec.resources     = "MobileAds/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"


Related Topics



Leave a reply



Submit