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
There are three main use scenarios for UnsafePointers
:
Function parameters
Creating a pointer to an existing variable
Allocating memory for the pointer