我在从 XPC 服务的块回调中传输 NSAttributtedString 时遇到了很大的问题。
我正在尝试将基本字符串返回为:
NSDictionary *arrayComa = @{NSForegroundColorAttributeName:[NSColor colorWithRGB:0xD35250],
NSFontAttributeName:[NSFont fontWithName:@"Monaco" size:11]};
NSMutableAttributedString *testString = [[NSMutableAttributedString alloc] initWithString:@"{}" attributes:arrayComa];
我还将传入的响应列入白名单:
let incommingClasses:Set = Set(arrayLiteral: [NSMutableAttributedString.self, NSAttributedString.self, NSColor.self, NSFont.self, NSString.self, ])
connectionService.remoteObjectInterface?.setClasses(incommingClasses, forSelector: attributtedText:withReply:, argumentIndex: 0, ofReply: true)
我做什么都会得到错误:
Exception caught during decoding of received reply to message 'Exception caught during decoding of received reply to message 'attributtedText:withReply':, dropping incoming message and calling failure block.
Exception: Exception while decoding argument 0 (#1 of invocation):
<NSInvocation: 0x6000006649c0>
return value: {v} void
target: {@?} 0x0 (block)
argument 1: {@"NSMutableAttributedString"} 0x0
Exception: value for key '<no key>' was of unexpected class 'NSMutableAttributedString'. Allowed classes are '{(
(
NSMutableAttributedString,
NSAttributedString,
NSColor,
NSFont,
NSString
)
)}'。
有人通过 XPC 服务成功传输了 NSAttributtedText 吗?