I cannot find any samples on how to get CPointer in Kotlin Multiplatform, and the documentation that exists doesn't help much. In my iOS source set, I need to build the Kotlin equivalent of the following Swift code (only including relevant parts of the code):
...(hex: String) {
if hex.hasPrefix("#") {
let start = hex.index(hex.startIndex, offsetBy: 1)
let scanner = Scanner(string: hexColor)
var hexNumber: UInt64 = 0
if scanner.scanHexInt64(&hexNumber) {
r = CGFloat((hexNumber & 0xff000000) >> 24) / 255
....
The specific part I am having problems with is
scanner.scanHexInt64(&hexNumber)
This is the Kotlin code and the question
//input to function - hex: String
val scanner = NSScanner(hex)
if (hex.startsWith("#")) {
scanner.scanLocation = 1u
}
var hexNumber : UInt32 = 0u
/*Type mismatch.
Required:
CPointer<UIntVar /* = UIntVarOf<UInt> */>?
Found:
UInt32 /* = UInt */
*/
//HOW TO GET CPOINTER TO hexNumber?
scanner.scanHexInt(hexNumber)
Per documentation: (link)
Pointers and arrays are mapped to
CPointer<T>?.
But how?