0

I am facing some issues on the last two days and I didn't find anything on Internet that help me to solve them.

Here's the problem:

  • I have a custom iOS framework of my own
  • I have two different Xcode projects that use this custom framework
  • In the first project, there is no problem, everything works perfectly
  • In the second project, I get a Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[** **:]: unrecognized selector sent to instance 0x101b02f90' when I am calling a method which is also called in the first project and which works perfectly in the first project
  • Both projects use the same custom iOS framework version and build

During the last two days, I have tried the followings:

  • Clean project > Clean build project > Rebuild project - Doesn't work
  • Rebuild the framework and add into the two projects - The issue still there

One thing that is very weird is that I have print the methods available in my frameworks in both projects according to this Stack Overflow, in the first project I have 130 methods available, in the second one I have only 72 methods available.

Is anyone have a clue of what happen?

Regards,

Jeremy

IMACODE
  • 125
  • 2
  • 9
  • is it objc? or swift? on objc you might need to add for loading the -load_all or -force_load on the projects loading it so you get the symbols...? – Joerg Simon Apr 18 '18 at 10:42
  • The apps are in swift, the framework is in objc. Where I should add this flags? – IMACODE Apr 18 '18 at 10:44

2 Answers2

2

sry, I just saw you first question/answer now.

The main reason you need to do that is because of categories or other dynamic elements in static libraries. Objective C has Categories which are approximately the same as extensions in Swift, so you can extend classes/objects with additional methods.

In Objective C you can create a static library to link into you project. Without this flag however (-ObjC general of -force_load for a specific library) the symbols of Categories are not loaded outside of the library. I guess an original motivation was to use categories for internal stuff, so the default is not to load them. That also makes the binary a bit smaller. However many libraries actually add Categories (==Extension) they want to expose, so usually you need on of the flags.

Hope that helped a bit ^_^.

Joerg Simon
  • 421
  • 2
  • 7
0

I finally find out what was causing the issue. I need to add -ObjC flag in "Other Linker Flags" in the Build Settings of the second project.

I don't understand why without this flag the framework has only 72 methods, and with the flags all the methods are available. Someone has an idea?

IMACODE
  • 125
  • 2
  • 9