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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift iOS Programming for Kids

You're reading from   Swift iOS Programming for Kids Help your kids build simple and engaging applications with Swift 3.0

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781787120747
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Steffen D. Sommer Steffen D. Sommer
Author Profile Icon Steffen D. Sommer
Steffen D. Sommer
Jim Campagno Jim Campagno
Author Profile Icon Jim Campagno
Jim Campagno
Arrow right icon
View More author details
Toc

Our first class

Go ahead and create a new Xcode playground and delete the autogenerated content. Let's continue with our example of modeling a person by adding the following to our playground:

class Person {
 
}

Note

All related source code for this chapter can be found here: https://github.com/swift-book-projects/swift-3-programming-for-kids/tree/master/Chapter-9

Let's take a look at the simple code we just wrote. The class keyword is how we define a class in Swift. Remember that a class is our abstract representation of something we are trying to model and the object is the instance of our class. Next, Person is the name of our class, and is also called our type. In Swift, we capitalize the names of our classes. This is similar to other types we have seen so far, such as String and Int; the difference being that this is a type that we define ourselves.

If we want to instantiate our new class that does not hold any functionality, we will do...

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