I have a pair of Swift Xcode targets that implement the XPC main app service app pattern. I figured out how to pass custom classes back and forth, either as arguments to the remote object's methods or "return values" (i.e., arguments the completion handler/reply block). This all works well.
Now I am trying to add a new wrinkle: call the completion handler with an NSArray of my custom classes from the service to return them to the main app. I understand from
it would be needed if your published interface looks like
@objc func ReadAllSnapshotsRpc(then completion: @escaping (NSArray?, Error?) -> Void)
i.e. if you would return an opaque array of unknown what, but you return explicitly typed object, so everything else is on NSSecureCoding
as stated.
Update: the reason as error stated is in decoding - for decoding all class should be enumerated. Below is fixed variant:
public required init?(coder: NSCoder) {
guard
let partials = coder.decodeObject(of: [NSArray.self, PartialSnapshot.self], forKey: "partials") as? [PartialSnapshot]
else {
NSLog("ReadAllSnapshotsRpcReturnType: returning nil from init?()")
return nil
}
self.partials = partials
}