I want to send struct data from my watchOS-app to my iOS-app using WatchConnectivity. As I have understood, you can only send property list objects, hence I must convert my struct somehow. I tried converting it into a NSDictionary, and also make it a Codable struct, but it doesn't work since I have properties that does not conform to the Codable prototocols. Any suggestions on how this can be solved in a good way?
I'm using XCode Version 10.1 and Swift 4.2.
Here is my struct:
struct Storage {
var acc: Acc
struct Acc {
var x: [Double] = []
var y: [Double] = []
var z: [Double] = []
}
var gyro: Gyro
struct Gyro {
var x: [Double] = []
var y: [Double] = []
var z: [Double] = []
}
var mag: Mag
struct Mag {
var x: [Double] = []
var y: [Double] = []
var z: [Double] = []
}
var pulse: [Double] = []
var quaternion: Quaternion
struct Quaternion {
var w: [Double] = []
var x: [Double] = []
var y: [Double] = []
var z: [Double] = []
}
}
I tried [making] it a
struct, but it doesn't work since I have properties that does not conform to theCodable
prototocolsCodable
Right, but these properties are composed of types that are easy to make codable. If you add a
Codable
conformance to
Storage
and all its nested typed (
Acc
,
Gyro
,
Mag
and
Quaternion
), then the compiler will synthesise the entire implementation.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"