【发布时间】:2020-04-28 15:39:35
【问题描述】:
我找不到任何关于如何在 Kotlin Multiplatform 中获取 CPointer 的示例,并且现有的文档没有多大帮助。 在我的 iOS 源代码集中,我需要构建与以下 Swift 代码等效的 Kotlin 代码(仅包括代码的相关部分):
...(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
....
我遇到问题的具体部分是
scanner.scanHexInt64(&hexNumber)
这是 Kotlin 代码和问题
//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)
根据文档:(link)
指针和数组映射到
CPointer<T>?.
但是怎么做呢?
【问题讨论】:
标签: c swift kotlin kotlin-multiplatform kotlin-native