-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Swift
By :

The most basic way in which we can group together data and functionality in a logical unit or object is by defining something called a structure. Essentially, a structure is a named collection of data and functions. Actually, we have already seen many different structures because all of the types, such as a String, array, and dictionary, which we saw previously, are structures. Now, you will learn how to create your own structure.
Let's jump straight to the topic of defining our first structure so that it represents a contact:
struct Contact { let firstName: String = "First" let lastName: String = "Last" }
Here, we created a structure using the struct
keyword followed by a name and curly brackets ({}
) with some code within them. Just as with a function, everything about a structure is defined within its curly brackets. However, code within a structure is not run directly, it is all part of defining what the structure is. Think...
Change the font size
Change margin width
Change background colour