Adam
Adam

Reputation: 33146

Xcode can't see a Class Extension Header even though I've imported it

After going round in circles for ages on this one, I'm asking and self-answering for future readers:

  1. Create a class in Xcode (.h and .m)
  2. Create a Class Extension in Xcode (.h)
  3. ...do something in that class extension...
  4. Import the Class Extension to the class it extends (in the .m)
  5. Import the Class Extension to a different class
  6. Reference something - anything - in that different class
  7. ...Xcode compiler error: can't find / see / act upon the contents of the Class Extension

Upvotes: 0

Views: 442

Answers (1)

Adam
Adam

Reputation: 33146

Took me ages and ages to see this, I couldn't find any hits on SO, but the cause is:

Issue in Apple's "create class extension" template, IF the project was ORIGINALLY created as a static-library:

By default, instead of #import'ing the class you're extending, it #import's the library's global file - which might be what you want (if you want to export this class header), but which may or may not contain that header.

To fix it, manually #import the original class's header into the class-extension, and your sanity will be restored.

Upvotes: 1

Related Questions