Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you reference Xib files from static libraries on the iPhone?

In my app, i currently have all my code separated into a static library, to make it easier to set up the xcode project targets for the actual app and for unit tests for my code. The problem with this is that i want to put most of my xib files in the static library as well, but it seems that when i run my app and try to reference the xib it can't find it unless it is included in the actual app's target instead of the static library target. Is it possible to have xib files and other resources included in static libraries that can be referenced by code in that same library, and if so, how?

like image 958
Kevlar Avatar asked Apr 01 '09 21:04

Kevlar


4 Answers

Reply to comment (won't fit in comment box)

No worries, I've been trying to do pretty much the same thing as you for the last week - I'd like to ship a "framework" of xibs, include files and .a libs to a client without giving them all the source code. I couldn't find a good way to do this with bundles either.

For whatever reason, Apple are being particularly obtuse about this - I can't see a reason for them to be so in the case of static libraries (dynamic libraries fair enough).

My solution for now is to manually create a package folder "Foo" that contains the following subfolders:

  1. "include" -> put .h files here
  2. "res" -> put .xib files here
  3. "lib" -> contains "iphoneos" & "iphonesimulator" subfolders each with libFoo.a

Then zip this up and send to the client. The client then:

  1. Unzips the package where ever they like.
  2. Adds the "res" folder under the resources group.
  3. Changes the following target settings:
    Other Linker Flags = -Objc -lfoo
    Header Search Paths = /include
    Library Search Paths = /lib/$(PLATFORM_NAME)

I can probably automate the package creation with some build steps at my end, but the client is stuck with four slightly fiddly steps to get set up.

like image 142
Justicle Avatar answered Oct 02 '22 18:10

Justicle


I found a perfect solution for this that does all the above automatically and more https://github.com/kstenerud/iOS-Universal-Framework Its an xCode plugin

It worked for me like a charm, It works only for XCode 4 and above

like image 38
Ronen Morecki Avatar answered Oct 02 '22 18:10

Ronen Morecki


Yes You can. add a xib file in your library as you would do for any normal project. Then in library project target add the xib file in copy Files section along with .a file. In your main project where you are using the library, drag and drop the xib file where .a file for library is located.

like image 39
Tushar Vengurlekar Avatar answered Oct 02 '22 17:10

Tushar Vengurlekar


Answer in including Xib files to your static library.

This time we have Xcode 11, you just create a bundle target in addition to your library target. The bundle template is available on macOS. Then from the library code, reference the bundle to be able to reference the nib. You distribute the library with the bundle.

A detailed video about using Xibs with static libraries below: https://www.youtube.com/watch?v=WQI02KR9kQw

like image 40
naz Avatar answered Oct 02 '22 16:10

naz