I am trying to use NSXPCConnection in swift.
So, this line:
_connectionToService = [[NSXPCConnection alloc] initWithServiceName:@"SampleXPC"];
can be replaced by this line:
_connectionToService = NSXPCConnection(serviceName: "SampleXPC")
And, this line:
_connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(StringModifing)];
can be replaced by this line:
_connectionToService.remoteObjectInterface = NSXPCInterface(protocol: <#Protocol#>)
Now I am confused about using the correct replacement for: <#Protocol#> in swift, in objective c I would have used: @protocol(StringModifing), but in swift I am clueless :(
That's a tricky one.
First of all protocol is a reserved keyword and cannot be used as parameter label. A quick look into Apples official doc helped me here. use `protocol`` instead. That means the parameter name contains single quotes.
"[obj class]" is being replaced by "obj.self" in swift. The same syntax is used for protocols. That means in your case "@protocol(StringModifing)" becomes "StringModifing.self".
Unfortunately this still will not work. The problem now is behind the scenes. The xpc mechanism is some kind of low-level stuff and wants ObjC style protocols. That means that you need the keyword @objc in front of your protocol declaration.
All together the solution is: