Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering macOS Programming

You're reading from   Mastering macOS Programming Hands-on guide to macOS Sierra Application Development

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781786461698
Length 626 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Stuart Grimshaw Stuart Grimshaw
Author Profile Icon Stuart Grimshaw
Stuart Grimshaw
Gregory Casamento Gregory Casamento
Author Profile Icon Gregory Casamento
Gregory Casamento
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Hello macOS 2. Basic Swift FREE CHAPTER 3. Checking Out the Power of Xcode 4. MVC and Other Design Patterns 5. Advanced Swift 6. Cocoa Frameworks - The Backbone of Your Apps 7. Creating Views Programmatically 8. Strings and Text 9. Getting More from Interface Builder 10. Drawing on the Strength of Core Graphics 11. Core Animation 12. Handling Errors Gracefully 13. Persistent Storage 14. The Benefits of Core Data 15. Connect to the World - Networking 16. Concurrency and Asynchronous Programming 17. Understanding Xcodes Debugging Tools 18. LLDB and the Command Line 19. Deploying Third - Party Code 20. Wrapping It Up

Arrays, dictionaries, and sets


Swift offers a comprehensive set of collection types, as one would expect. In common with many other languages, each of these collection types will only hold values of the same type. Thus, the type of an Array of Int values is distinct from the type of an Array of Float values, for example. If you're coming from Objective C, you may quickly come to appreciate the type safety and simplicity of Swift Array objects over NSArray.

There are no separate mutable and immutable collection types, as such, since all objects in Swift can be declared with either var or let.

Arrays

Arrays are zero-based, and look like this:

let myArr = [21, 22, 23] 

They are equipped with a pretty standard set of methods, such as count and accessor methods:

let count = myArr.count // 3 
let secondElmt = myArr[1] // 22 
let firstElmt = myArr.first // 21 
let lastElmt = myArr.last // 23 

Elements are set, logically enough, as follows:

myArr[1] = 100 

They are a lot more convenient to work with than...

You have been reading a chapter from
Mastering macOS Programming
Published in: May 2017
Publisher: Packt
ISBN-13: 9781786461698
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 $19.99/month. Cancel anytime
Banner background image