Sorry, in order to call mocl from swift you must first create wrapper methods in Objective-C that enclose the desired calls. For example:
- (void)formatHello:(NSString *)arg {
format_hello(arg);
}
then formatHello can be called from swift. Note: in the future mocl could autogenerate swift bindings, but for now, it is a manual process.
- Wukix, 1754 days ago
Thanks for help! It would be awesome if mocl could generate swift bindings.
Meanwhile here's how I did it:
1. Create new Objective-C file mocl_bridge.m
2. Open mocl_bridge.m and add following:
#import <Foundation/Foundation.h>
#import <CoreGraphics/CGBase.h>
#import "mocl.h"
NSString* formatHello(NSString *arg) {
return format_hello(arg);
}
3. Edit Project settings > Swift Compiler - Code Generation > Objective-C Bridging Header, add mocl_bridge.m (include relative path to file if needed)
4. Edit button action method in ViewController.swift:
@IBAction func btnHelloAction(sender: AnyObject) {
let name = txtField.text
lblHello.text = formatHello(name);
}
Now it should successfully compile and run.