Press "Enter" to skip to content

Tag: swift 3

Pointers in Swift 3

Let’s reverse a null-terminated string in Swift. First, the code.

This example is a bit contrived, if you wanted to reverse a string in Swift it would be much easier to use the String(reverse.characters.reversed()) method. First thing, when working with pointers in Swift, is to allocated memory for them. Here I’m using ptrCapacity to allocate space for the array of CChar that will represent the string we are going to reverse. ptrCapacity in this case will be the same size of reverse.characters.count, however I wanted to have a reminder there of MemoryLayout. MemoryLayout helps describe the memory layout of…

Continue reading Pointers in Swift 3