XPC template 使い方 メモ
少し勉強.
[Add Target] -> [XPC Service] で
テンプレート *.h, *.Protocol.h を作成.
Target -> Build Phases -> Embed XPC Services (*.xpc)を確認
[File] -> [New] -> [Objective-C File] で ブリッジヘッダを作成.
XPC Service の ヘッダファイルをブリッジヘッダに追加
テンプレート *Protocol.h 内のコメントに従って使う.
Swift で使う場合に 下例のように remote object をキャスト.
var _connectionToService : NSXPCConnection! _connectionToService = NSXPCConnection(serviceName: "na.partB") _connectionToService.remoteObjectInterface = NSXPCInterface(with: partBProtocol.self) _connectionToService.resume() let remoteObj = _connectionToService.remoteObjectProxyWithErrorHandler({ (err) in let alert = NSAlert(error: err) alert.alertStyle = NSAlertStyle.critical alert.runModal() }) as! partBProtocol remoteObj.upperCaseString("hello", withReply: { (rep) in print(rep!) }) // _connectionToService.invalidate()