2

I created a custom NSTextView subclass called JWTextView. It's part of a separate Xcode project. That project has a target that creates a static library containing this class. I now added this subproject to my main project under MainProject/Libraries/JWKit (in Finder) and added it in Xcode as well. I made my main project's target depend on the subproject's library target and I'm linking the library in my main target. I also added MainProject/Libraries/** to the Library and Header search paths.

Now I'm trying to use this view in my main project. I added an NSTextView to one of my xib's and changed its class to JWTextView. I also have an IBOutlet JWTextView in my code and call some methods on it upon user interaction. JWTextView.h is imported. Everything compiles file.

But once I call a method on this text view that I implemented in my JWTextView subclass, the app crashes with an unrecognized selector error:

-[NSTextView myCustomMetod:]: unrecognized selector sent to instance 0x101901a80

I checked, and it's actually an NSTextView instance, even tough the ivar is a JWTextView and I set the class in IB.

If I just add the classes to my main project it works fine, but not as a subproject and a static library.

Jawap
  • 2,463
  • 3
  • 28
  • 46
  • Found a solution here: http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime – Jawap Dec 08 '12 at 17:09

1 Answers1

0

The compiler optimized it out, because I wasn't referencing the class anywhere by name (except the ivar, which doesn't seem to help).

Adding [JWTextView class]; to applicationDidFinishLaunching: fixed the problem.

Jawap
  • 2,463
  • 3
  • 28
  • 46
  • 1
    How about using the `-ObjC` linker switch instead of your workaround when linking your library into the application target? – Till Dec 08 '12 at 17:06