Advanced Swift 3 - Part 13: Unsafe Memory Access | Ray Wenderlich

By default, Swift is memory safe; it prevents access to uninitialized raw memory. Learn how to circumvent this safety when interfacing with an unsafe language or gain performance.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3810-advanced-swift-3/lessons/13

This video was absolutely amazing. It’s rare to find somewhere teaching this level of swift, please make more advanced stuff like this in the future and keep up the great work!

Thanks for the encouragement. Glad you are finding it useful.

It is really great to find such video and advance my knowledge, but I am wondering what would be a real-world case in your opinion for using unsafe pointers ?

Thank you! There are a couple of use cases I can think of.

The two common ones are: (1) when you are interacting with an unsafe language such as C. Check out the challenge exercise. Also, in the error handling video, there is an example usage there.

You might also use unsafe pointers when you want additional speed. These guys aren’t reference counted and don’t incur any of that cost. (The Swift 4 ownership model may make this a little easier.)

Finally, if you are ever doing something like a device where you need fast access to uninitialized blocks of memory.