0

I have imported an Objective-C library with its entire source code in my Xcode project. The recommended way of using this library is to subclass its main object and customise its behaviour. The problem is that this superclass has many properties declared in the .m through the well known mechanism:

@interface BGRichTextEditorViewController ()


@property (strong) NSString *theString;

@end

This way, they are invisible by my subclass, and all I can do is either change the code of the library and move the properties to the .h or use valueForKey to access the superclass properties from the subclass. Is there a more elegant way to solve this ? Many thanks

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Alfonso Tesauro
  • 1,730
  • 13
  • 21
  • https://stackoverflow.com/questions/19095716/hiding-properties-from-public-framework-headers-but-leaving-available-internall ? Make the subclasses know the "private header"?, which is what's currently in the .m That's a possible solution. – Larme May 04 '20 at 16:56
  • Please don't spam tags. Your question has nothing to do with Swift, iOS, macOS or Cocoa, it is a plain Objective-C language question, so only use that tag. – Dávid Pásztor May 04 '20 at 17:02
  • I am sorry David I will keep it mind for the future. Regarding the Swift tag, I used it because when properties are created in the .m, they are also invisible to Swift, since the bridging header only imports the .h. Sorry again and thanks for your comment. – Alfonso Tesauro May 04 '20 at 17:05

1 Answers1

1

That is a class Extension. The public interface is in the header file, and the private properties are hidden from you. It is by design by whoever wrote the library.

If you work around this with valueForKey you might very well find your code breaking on a new release of the library (They are usually private for a reason).

If you have the source code and don't need to be on the bleeding edge release, I would simply fork the library and make your own changes.

davbryn
  • 7,156
  • 2
  • 24
  • 47