Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS static library does not work

I followed the instructions in this article to create a static library:

http://developer.apple.com/library/ios/#technotes/iOSStaticLibraries/Articles/creating.html

I built it for iPhone simulator target. It built successfully, then I imported into a new project where I wanted to use it. It imported fine and there are no problems, but the library doesn't work. There are no library methods that I'm calling; rather the purpose of the library is to swizzle the UIViewController viewDidAppear method so that a piece of code gets executed every time a UIViewController appears. This piece of code is not getting called, despite my library being included in the "Link Binary With Libraries" build phase.

I know the problem isn't with the code itself because if I import the raw .m and .h source files not as a library, everything works fine.

like image 287
raviparikh Avatar asked Feb 05 '26 08:02

raviparikh


1 Answers

Did your library contain any categories?

If so, I think you should follow these steps to get it work:

  1. In Xcode, double-click the target's name under "Targets" in the Project window.
  2. Choose the Build Settings panel.
  3. Scroll down to the "Other Linker Flags" build setting under the Linking collection and set its value to "-all_load -ObjC".

Please refer to corresponding Apple Documentation

Here is a related question: Objective-C categories in static library

like image 77
lmnbeyond Avatar answered Feb 06 '26 22:02

lmnbeyond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!