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
Swift Essentials

You're reading from   Swift Essentials Get up and running lightning fast with this practical guide to building applications with Swift

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781784396701
Length 228 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Bandlem Limited Bandlem Limited
Author Profile Icon Bandlem Limited
Bandlem Limited
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Swift classes, protocols, and enums

Almost all Swift applications will be object oriented. Chapter 1, Exploring Swift, and Chapter 2, Playing with Swift, both demonstrated functional and procedural Swift code. Classes such as Process from the CoreFoundation framework, and UIColor and UIImage from the UIKit framework were used to demonstrate how classes can be used in applications. This section describes how to create classes, protocols, and enums in Swift.

Classes in Swift

A class is created in Swift using the class keyword and braces are used to enclose the class body. The body can contain variables called properties as well as functions called methods, which are collectively referred to as members. Instance members are unique to each instance, while class members are shared between all instances of that class.

Classes are typically defined in a file named for the class; so a GitHubRepository class can be defined in the GitHubRepository.swift file. A new Swift file can be created by navigating...

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 $19.99/month. Cancel anytime
Banner background image