Search code examples
iosswiftevernotebridge

I there a way, to view the exposed Objective-C header to swift


I have problems to understand, why some member functions from an imported (and complicated) set of Objective-C interface are not available in Swift.

I have a Bridging-Header File:

#import "EvernoteSDK.h"

and I can't use some member functions in my ViewController

let userStore = EvernoteUserStore()
userStore.initWithSession(session)

initWithSession is not available for the swift code, but why?

The objective-C header shows:

@interface EvernoteUserStore : ENAPI
+ (instancetype)userStore;
- (id)initWithSession:(EvernoteSession *)session;

If I could view the exposed Objective-C header, I may understand, how the mangling works


Solution

  • In Swift the initializer call is combined with the constructor. In other words, Objective-C's

    EvernoteUserStore *userStore = [[EvernoteUserStore alloc] initWithSession:session];
    

    becomes

    let userStore = EvernoteUserStore(session:session);
    

    The tool recognizes the initWithSomething: name of Objective-C, and converts it to

    init(something something : SomeType)
    

    In case of EvernoteUserStore the corresponding init method looks like this:

    init(session session: EvernoteSession!)