Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Swift High Performance

You're reading from   Swift High Performance Leverage Swift and enhance your code to take your applications to the next level

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781785282201
Length 212 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Koval Koval
Author Profile Icon Koval
Koval
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Swift High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Exploring Swift's Power and Performance 2. Making a Good Application Architecture in Swift FREE CHAPTER 3. Testing and Identifying Slow Code with the Swift Toolkit 4. Improving Code Performance 5. Choosing the Correct Data Structure 6. Architecting Applications for High Performance 7. The Importance of Being Lazy 8. Discovering All the Underlying Swift Power Index

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 parameters

  • Creating a pointer to an existing variable

  • Allocating memory for the pointer

Function parameters

First let's learn how to use pointers. When designing your API in Swift, you shouldn't use UnsafePointers, but you can find a situation...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images