我正在通过 Obj-C 代码转换为 Swift,但是从最近 2 天开始,我卡在了 Obj-C 代码下方的第三行。
char encodedChar = (int)c + (int)kc;
NSLog(@"Encoded Char : %c", encodedChar); //prints like, Î, ¾, Ü etc.
const void *pt = &encodedChar;
[encodedData appendData:[NSData dataWithBytes:pt length:1]];
这是我的 Swift 代码,
let encodedChar = "\(character)".toInt()! + numbers[index]
let characterString = String(stringInterpolationSegment: UnicodeScalar(encodedChar))
println("Encoded Char String : \(characterString)") //prints same, Î, ¾, Ü etc.
但是接下来,什么是 swift 等价于:const void *pt = &encodedChar;
我不想将我的字符串转换为 NSData。因为它的行为不同。
任何建议都会有帮助,谢谢:)
最佳答案
得到答案,
var encodedChar = "\(character)".toInt()! + keyNumbers[index]
let data = NSData(bytes: &encodedChar, length: 1)
encodedData.appendData(data)
关于ios - Swift 中的字符指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30093220/