Sam
12/17/2019, 5:25 PMNative interop types constructors must not be called directly
when compiling this bit of code:
val nsError: NSError? = null
val nsErrorPtr = ObjCObjectVar<NSError?>(nsError.objcPtr()).ptr
val decoder = NSKeyedUnarchiver(forReadingFromData = data, error = nsErrorPtr) //Error is generated by this line.
This should be a valid constructor but it is throwing that compiler error.basher
12/17/2019, 5:29 PMSam
12/17/2019, 5:47 PMSam
12/17/2019, 6:35 PMclass AuthTokenContainer(val authToken: AuthToken) : NSObject(), NSCodingProtocol {
override fun encodeWithCoder(coder: NSCoder) {
//Several encoding method calls
}
override fun initWithCoder(coder: NSCoder): NSCodingProtocol? {
//coder.decodeXXX methods omitted
val authToken = AuthToken(access, scope, expires, identification, refresh)
return AuthTokenContainer(authToken)
}
}
Sam
12/17/2019, 6:40 PMval data = NSData.create(base64EncodedString = dataString, options = NSDataBase64Encoding64CharacterLineLength)
?: return null
return when (val container = NSKeyedUnarchiver.unarchiveObjectWithData(data)) {
is AuthTokenContainer -> {
container.authToken
}
else -> null
}