I am trying to add xib file or any other view controller file within static library but I can't do so. Can you please help me?
If possible please add the whole source code
their is button on first view. And when clicking on that button, new view controllers comes up with something (lets say changes in background color). How to create static library for this? so that I may use it in another project?
Thanks in advance
Strictly speaking, it's correct that you cannot add a Xib to a static library. However, there are workarounds. Matt Galloway's iOS Library With Resources tutorial will show you how to do just that.
See iOS Library With Resources.
If you want to build your interfaces using interface builder when building a static library you will need to make a bundle and distribute it with your library.
In Xcode:
Then you need to get your bundle compiled at the same time as your framework. Add the bundle to the "Target Dependencies" build phase of your framework.
When you make your xibs you make their target this new bundle you have created.
Then when you compile your framework in the derived data directory, next to your framework binary you will find your compiled bundle. You give this to your third parties along with the framework binary.
So how do you reference this bundle in your code? In iOS bundles cant be loaded and your bundle will actually be inside the third party's iOS application main bundle. You can create a category on NSBundle for conveniently accessing your bundle from your code:
You can then access your bundle in code to load xibs like this:
Remember that if you use categories in your framework code you will need to make sure that your framework consumers add the
-ObjC
(or-all_load
if not using a recent Xcode) "other linker flag" to their projectsXIB is like resource and what static library is , a compiled file that contains ur classes. You can say it is your compiled code ready to be used. You can not add xib's to static library.