4
在C我會做這樣的事情如何使用UnsafeMutableBufferPointer
int count = 10;
int *buffer;
num = malloc(count * sizeof(int));
for (int i = 0; i < count; i++) {
buffer[i] = rand();
}
我見過UnsafeMutablePointer像這樣使用
let buffer = UnsafeMutablePointer<Int>.alloc(count)
for i in 0..<count {
buffer[i] = Int(arc4random())
}
如何使用UnsafeMutableBufferPointer在斯威夫特一個C風格的緩衝?另外,我將如何爲指針重新分配更多空間?
嗨Khadpe,我有幾天的相對問題,請幫忙:http://stackoverflow.com/questions/36662378/testcase-failed-after-converting-codes-from-objective-c-to-swift –