I have a class:
final class XpcMaker<T: Protocol>: NSObject
{
private let exchangerProtocol: T
init(exchangerProtocol: T)
{
self.exchangerProtocol = exchangerProtocol
super.init()
}
func exchangeProxyAndConnection() -> (Any, NSXPCConnection)
{
let connection = NSXPCConnection(machServiceName: "... some name ...")
connection.remoteObjectInterface = NSXPCInterface(with: exchangerProtocol.self)
let proxy = connection.remoteObjectProxyWithErrorHandler() {...}
connection.resume()
return (proxy, connection)
}
}
I want to return proxy as T (instead of Any). I tried:
Cannot find type 'exchangerProtocol' in scope
guard let goodProxy = proxy as? exchangerProtocol else
guard let goodProxy = proxy as? exchangerProtocol.self else
'self' is not a member type of type 'T'
guard let goodProxy = proxy as? T.self else
This compiles, but always enters the else-branch at run time:
guard let goodProxy = proxy as? T else
So: How to return my proxy as T ?