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

Safety


Swift is designed for safety. It eliminates many issues of compile time. Here is a list of things that Swift handles for you:

  • Type safety: Swift is very strongly typed language. If a function has the Int parameter, you must pass Int as an argument when you call it. This rule also applies to operators. Swift doesn't allow use of the wrong type:

    func increase(x: Int) -> Int {
      return x + 1
    }
    
    let x = 10
    let percent = 0.3
    let name = "Sara"
    
    x + name //Error, can't apply + operator for Int and String
    x * percent //Error, can't apply * to Int and Double
    Double(x) * percent // 3
    
    increase(x) // 11
    increase(percent) // Wrong type
    increase(name) // Wrong type
  • Variables must always be initialized before use: Accessing non-initialized memory is a dangerous operation. Swift handles this problem in a very nice and safe way. It doesn't compile when you try to do that:

    var y: Int
    //y + 10 //Error, variable 'y' used before being initialized
    y = 1
    y + 10

    Constant values can't be changed after they...

You have been reading a chapter from
Swift High Performance
Published in: Nov 2015
Publisher: Packt
ISBN-13: 9781785282201
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