O'Reilly logo

Swift High Performance by Kostiantyn Koval

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Swift arrays and unsafe C arrays

Everyone knows that C is a super-fast programming language and when you hit a performance problem people go to C for help. In Objective-C, it is very easy to use C functions and types; its name says it all—C with Objects.

Swift also has support for interacting with C types and pointers. Even though it's available, it's considered as a dangerous operation because you need to do memory management manually. You need to allocate and destroy memory. Those types are called Unsafe in Swift and start with the Unsafe prefix—for example:

  • UnsafePointer
  • UnsafeMutablePointer
  • UnsafeBufferPointer

    Tip

    Avoid using C pointers in Swift. It adds a lot of complexity to the code.

There are three main use scenarios for UnsafePointers:

  • Function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required