In C, I would do something like this
int count = 10;
int *buffer;
num = malloc(count * sizeof(int));
for (int i = 0; i < count; i++) {
buffer[i] = rand();
}
I saw UnsafeMutablePointer which was used as
let buffer = UnsafeMutablePointer<Int>.alloc(count)
for i in 0..<count {
buffer[i] = Int(arc4random())
}
How to use UnsafeMutableBufferPointer for C style buffer in Swift? Also, how would I redistribute more space for a pointer?
joels source
share