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
Mastering Swift 3

You're reading from   Mastering Swift 3 Build incredible apps for iOS and OS X

Arrow left icon
Product type Paperback
Published in Oct 2016
Publisher Packt
ISBN-13 9781786466129
Length 392 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (23) Chapters Close

Mastering Swift 3
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Taking the First Steps with Swift FREE CHAPTER 2. Learning About Variables, Constants, Strings, and Operators 3. Using Swift Collections and the Tuple Type 4. Control Flow and Functions 5. Classes and Structures 6. Using Protocols and Protocol Extensions 7. Protocol-Oriented Design 8. Writing Safer Code with Availability and Error Handling 9. Custom Subscripting 10. Using Optional Types 11. Working with Generics 12. Working with Closures 13. Using Mix and Match 14. Concurrency and Parallelism in Swift 15. Swift Formatting and Style Guide 16. Swifts Core Libraries 17. Adopting Design Patterns in Swift

Putting it all together


To reinforce what we have learned in this chapter, let's look at one more example. For this example, we will create a function that will test to see if a string value contains a valid IPv4 address or not. An IPv4 address is the address assigned to a computer that uses the Internet Protocol (IP) to communicate. An IP address consists of four numeric values, ranging from 0-255, separated by a dot (period). An example of a valid IP address is 10.0.1.250:

func isValidIP(ipAddr: String?) -> Bool { 
 
    guard let ipAddr = ipAddr else { 
        return false 
    } 
     
    let octets = ipAddr.characters.split { $0 == "."}.map{String($0)} 
     
    guard octets.count == 4 else { 
        return false 
    } 
     
    func validOctet(octet: String) -> Bool { 
        guard let num = Int(String(octet)), 
            num >= 0 && num < 256 else { 
                return false...
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