I am creating an iOS Swift application using the Objective-C Framework.
Environment Header File (SMPort.h):
@interface PortException : NSException
{
}
@end
@interface PortInfo : NSObject
- (id)initWithPortName:(NSString *)portName_ macAddress:(NSString *)macAddress_ modelName:(NSString *)modelName_;
@property(retain, readonly) NSString *portName;
@property(retain, readonly) NSString *macAddress;
@property(retain, readonly) NSString *modelName;
@property(readonly, getter=isConnected) BOOL connected;
@end
@interface SMPort : NSObject {
void * m_port;
WBluetoothPort* wBluetoothPort;
BluetoothPort* bluetoothPort;
NSString * m_portName;
NSString * m_portSettings;
int m_ioTimeoutMillis;
BOOL checkedBlockSupport;
}
@property(assign, readwrite, nonatomic) u_int32_t endCheckedBlockTimeoutMillis;
- (void)getParsedStatus:(void *)starPrinterStatus :(u_int32_t)level;
I read the framework documentation and found this Objective-C code (which works fine):
@try
{
[starPort getParsedStatus:&status :2];
}
@catch (PortException *exception){
}
So, I tried to do something like this in Swift 2.1:
do{
try starPort.getParsedStatus(status , 2)
}
catch is PortException{
print("error")
}
But , when an error occurs , the compiler stops the application, stating that I did not catch this error:
2015-11-18 18: 59: 51.297 $$$$$ [$$$$$: $$$$$] * - 'PortException', : 'Native GetParsedStatusEx ' * : (0x2524a67b 0x36e76e17 0xa3af7 0x6f378 0x6f3d8 0x6fbc0 0x6fd10 0x6ef00 0x87bf8 0x87d80 0x29371559 0x293714e9 0x293594ff 0x29370e45 0x29370abf 0x2936947f 0x2933a561 0x29338bdb 0x2520dbff 0x2520d7ed 0x2520bb5b 0x2515f119 0x2515ef05 0x2e2fcac9 0x293a1f15 0x7f410 0x375e5873) lib++ abi.dylib: PortException
- :
func doGPS() throws { starPort.getParsedStatus(status ,2) }
func test() {
do {
try doGPS()
} catch is PortException{
print("Error")
} catch{
print("WTF? : \(error)")
}
}
test()
...
, Swift 2.1?
SMPort.h https://github.com/gabebear/receiptbooth/blob/master/StarIO.framework/Headers/SMPort.h