CBPeripheral
is a painful object to test as it can not be instanced by itself. Therefore, I'm using a wrapper (HBRPeripheralWrapper
) around it (also for other purposes).
I would like to forward most of call on the wrapper
(HBRPeripheralWrapper
) to the actual wrapped object CBPeripheral
.
It technically works using forwardInvocation
but how can I adopt a similar pattern in Swift
?
PS: NSInvocation
is not available in Swift
class HBRPeripheralWrapper {
let peripheral:CBPeripheral
// I would like to avoid this "manual" forwarding
var identifier: NSUUID {
get {
return peripheral.identifier
}
}
init(peripheral:CBPeripheral) {
self.peripheral = peripheral
}
// target forwarding is great, but how can I make the compiler happy?
override func forwardingTargetForSelector(aSelector: Selector) -> AnyObject? {
if(self.peripheral.respondsToSelector(aSelector)) {
return self.peripheral
}
return super.forwardingTargetForSelector(aSelector)
}
}