Press "Enter" to skip to content

Month: September 2016

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…

Custom Operators with Generics in Swift

This weekend I decided to sit back a play with Swift. About two weeks ago I took some time off from work and while relaxing I started watching Swift Talk. Swift Talk is a weekly video series by Chris Eidhof and Florian Kugler who during the show do a bit a pair programming and refactoring. Rather than go over a solution, they walk you through the thought process, live coding as they discuss the topic of the week. Even if you are not interested in Swift, as a coder I strongly suggest watching some of the free episodes to get…