Hi and welcome to the Complete iOS Development Bootcamp. This course is designed to be a one-stop shop for you to become an iOS developer. In designing this course I had the following matters in mind:
-
Covering the most up-to-date technology and methods.
-
Delivering everything that you need to know to develop advanced iOS applications ready for the market.
-
Instilling the attitude of problem-solving and making sure you know how to find your way on your own by the end of the course.
-
Covering almost all programming libraries related to iOS.
-
Providing numerous online and offline content to support your learning journey.
-
Providing tens of exercises and assignments to ensure you have enough practice.
-
Constantly updating the course based on students’ feedback.
-
Introducing all the best techniques of real developments.
-
Moving forward in the course and content complexity in a gradual manner that doesn’t overwhelm new programmers.
In developing this course I not only considered the beginner developers but also attempted to prepare it for those with intermediate iOS understanding or veteran programmers from other disciplines. In doing that, the course has been heavily subdivided. If you are totally new, it makes sense that you through the course lessons by lesson, but f you are already a programmer you can pick and choose on your own. hroughout this course, I covered a lot of different technologies and topics including but not limited to:
-
The very basics of developing an app
-
Use of XCode and customizing it
-
iOS Simulator
-
Basics to Advanced programming exercises
-
Basics to advanced user interface designs
-
Swift programming language at the depth
-
Handling touches and gestures
-
Use of graphics & Animations
-
Table views and Collection views
-
Version control
-
Device hardware features
-
Media
-
Networking
-
Maps and geolocation
-
Persistent data, Core Data & Realm
-
Accessing Web content
-
Notification
-
Sprite kit and 2D games
-
Scene kit and 3D games
-
Metal kit and low-level GPU
-
Augmented Reality Kit
-
Machine Learning Kit
-
Testing & Debugging
-
App store and Submissions
Throughout the course, I attempt to bring some of the best experiences I have gathered from years of teaching students to make sure you learn in the most efficient and the most useful way. In doing that I benefit from lessons, exercises, assignments, quizzes and external resources. I also stay available if you face any challenges and also constantly update the course content or add new ones depending on the feedback from students.
Prerequisites to join this course:
-
Basic understanding of how computers work.
-
Access to Internet
-
You would need a MAC OS Enabled computer. i.e. Mac, MacBook, MacBook Pro. iMac, etc.
-
Free IDE that you’ll get from Apple’s Website (XCode)
-
All programming and development matters will be covered in the course.
-
Preparation for loads and loads of new information
By the end of the course
-
Make real-life iOS Applications using advanced and relevant technology.
-
Be prepared to take on any iOS development challenges on your own.
-
Create various iOS applications with advanced User Interfaces, graphics, and animations as well as proper backend and data persistency.
-
Develop both 2D and 3D games (within iOS and XCode limitations)
-
Be prepared for iOS jobs and technical interview questions.
-
Write complex Swift code
-
Write complex Objective-c Code
-
Know how to convert Swift and Objective-C code into each other
-
Be familiar with loads of external libraries
-
Have hundreds of tiny apps at your disposal to develop larger scale applications
-
Develop market-ready apps for the industry.
-
Use Google technologies such as Firebase and Google Maps
-
Learn how to use Mac Command Line
-
Know how to use Cocopods to search and implement a variety of libraries and frameworks
-
Create your own iOS frameworks
Who is the target audience?
-
Anyone interested in developing iPhone / iPad apps (with or without any programming skills)
-
Experienced programmers who want to begin iOS development real quick.
-
Anyone who wants to focus on the programming side of iOS development.
Basic Programming
-
1Introduction
In this section, we will cover the following topics:
Hardware
Programming Languages
Different Software
Tool of Choice (XCode)
Use of iOS Simulator
Interface Builder
Developing a Very Basic App
Files In XCode
Some Basic Terminology
Using Text Views and Labels
Finally Getting Ready for Next Section
-
2Hardware
You would need to keep the following in mind regarding the hardware you’d need to be able to use this course:
You could use a Mac Machine or Laptop (potentially you can buy a mac mini)
Or you can install Mac Operating system on a Windows machine
You don’t need to have an iPhone device to actually use this course
-
3Software
Different software tools that one can use to develop an iOS app are also discussed. We briefly cover the advantages and disadvantages of each of them.
An important matter in here is learning that software alone is not enough. We would also need a programming language
A wide range of IDE software are used to develop iOS Applications. Some of them are as following:
XCode -> Apple default iOS IDE
Xamarin -> Microsoft cross platform (iOS, Android, Windows) IDE
PhoneGap -> HTML5 + Javascript iOS Development
Flutter -> Google’s new cross platform IDE
IDE stands for -> Integrated Development Environment
-
4Tools
Next we opt for XCode as our primary development tool. It’s an IDE that offers a wide range of options and it’s best suited for native iOS development.
We will have to download a version from Apple Developer Website and install it on our computer
XCode is equipped with various tools and programming languages and will take care of the debugging and running the app.
The following two programming languages could be used to develop iOS apps in XCode:
Objective-C (older and yet quite useful)
Swift (more modern and most commonly used)
-
5First App
For a very crude presentation, we start a new project in XCode and get a sense of what the different settings mean.
We will also realize where are two programming languages are located and how we are going to use them throughout this course
It’s important to notice that at this point, you might not understand a lot of these things and that’s perfectly fine
-
6XCode
Let’s have a look at some of the basics of XCode and try and understand how different things work together
XCode has 5 primary areas:
Text Editor
Toolbar
Utility Window
Navigation Window
Debugging Area
-
7Interface Builder
Interface Builder is used to design the visual elements of our iOS Apps
Having a look through how we make basic outlets and attributes editor of the interface builder. We will also look at the dimensions and get a starting sense of how the point system works.
In this lesson, we will make a Label that shows Hello World.
-
8Simulator
Simulator will compile our app. Compile is the process of converting your code and interface into an actual app. It is actually more advanced than this simple explanation, but this simple one will suffice for now. iOS Simulator is used to display the app in a device-like simulator. Simulators have both device and version. One could have different devices with different iOS versions. A simulator although very similar, it is not the exact as the phone device.
In this lesson, we'll get to simulate our app on different devices and different sizes. After trying different sizes, I suggested that you stick to only one as it will simplify your lives from now on.
In this lesson, we will also briefly touch on making a simulator a default one and also how to add or remove simulators.
-
9Understanding iOS
What’s the relationship between all these different files in XCode. What are they and how do they work? What should we wok on and how should we get comfortable working on our project? And also which files can be ignored for now?
In this early stages, there are only ever 3 files that are important for iOS App development. Those files are:
.storyboard file -> which is your visual design file
.m file -> which is the actual programming file of your application
.h file -> Which is the header file containing the declaration that also works as the connection between the .m and the .storyboard file
Build ~ Run ~ Compile -> Is the process of converting the iOS project in XCode into an iOS App in Simulator (or a physical device)
-
10Outlets
In this lesson, we will talk about outlast and how we can connect them to our app. Remember, it is not important to completely understand what is happening as this is more of an illustration
For now you can just copy paste my code. Everything about properties, dot operation, cycles, etc. will come later
-
11Text Views
In this lesson, we will play around with a textview in our interface builder. Text view is a container where you can add larger text content.
-
12Labels and Text Views Exercise
In this exercise you are supposed to develop an app that has a label that shows hello world and a text views that shows your name and the city where you live in as well as some details about your city. Try and format your text.
Don’t worry if you don’t get what’s happening. We will talk about all of this soon
-
13Label Rows Assignment
In this assignment you are supposed to develop an app interlace with 8 labels where all the gaps are the same.
Hint: Views have anchor points on their top left corner where the coordinates are x=0 and y=0. They then have width and height.
-
14The Very Basics Recap
-
15Very Basics Quiz
Basic User interface
-
16Introduction to Programming
In this section we will go through the basics of programming in Objective-C. We will discuss some basic definitions such as:
Variables
dot operations
Collections
Functions
We will then learn how to call a function and how to use it. By the end of this section, you should have a better understanding of how a piece of code in Objective-c actually works.
For most everything in here, we will work outside of iOS and we will work on developing command line tools.
-
17Command Line & Print
Command Line and Print
For practice purposes, we will rely on Command Line Tool projects from Mac OS templates. These are projects that can be utilized on Mac Terminal and act as command line tools. They compile a lot faster and help us speed up our learning process. We use
NSLog ( “” );
to print values into the XCode’s debugger console. NSLog prints whatever it finds within its two quotation marks identically to the console. We can format different value types to appear within NSLog.
-
18Comments
Comments
Commenting is the process of leaving notes for yourself or your co-workers within the body of the code. This way you can write all of your learning in the program as well.
The compiler which is in charge of debugging and converting your code into an application (or a tool) will go through your program line by line. Whenever it encounters two forward slashes ( // ) or a forward slash followed by an asterisk ( /* ), the compiler will know to ignore that line (or lines) of code.
-
19Basic Variables
Basic Variables:
There are four basic variables that we covered in this lesson. These four are:
Int (used for whole number variables such as 5, -9, 10)
Float (used for numeric values with a decimal part such as 3.3, -9.8)
Bool (used for true, false status such as game being paused or downloaded being finished or not)
Char (used to demonstrate a single character such as ‘a’, ‘b’)
We can print different variables by formatting them correctly for NSLog. The simplest of conversion are as following
NSLog(@”%i”, 5); // used to print an integer
NSLog(@”%f”, 5.5); // used to print a float
For a complete list of all possible formatting, please refer to the following document:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
-
20Variable Examples Exercise
In this exercise, we have to find examples of things that are of the type char, int, float and bool.
-
21Strings
Strings:
Strings are a series of characters joined with one another
We use strings for most of the text values
String is the default value that NSLog attempts to print
We can use methods such as stringWithFormat to format a variable or value into a string and to print them (or show them on a text enabled outlet)
Every variable has a declaration phase and a definition phase. Variables by nature have a changing status and their values change. That is the definition of them.
In declaring NSStrings unlike the previous variables, we use an asterisk. That is to make sure that the string is declared as a pointer. Pointers are really just an address for a space in memory and they are small pieces of data. If we had to store and copy the data being pointed to, we might very quickly run into problems of not having enough memory.
-
22Append Strings Exercise
Appending Strings:
We can append two NSStrings by using the stringWithFormat
We could also append them by using stringByAppendingString
We could also use a mutable string:
Mutable strings are modifiable. We can change the content of the string without the need to re-write them again
In mutable strings we can benefit from appendString method
Like most everything else in Objective-C, we use the square brackets for calling a method such as
[myMutableString appendString: @”some new string”]
-
23Variables In iOS
Variables in iOS:
Using variables in an iOS app is identical to that of a command line tool. Except when in iOS, we usually need to display our results in some sort of visual interface. In our example, we concatenated multiple variables by formatting them into strings and finally displayed them on a Text View.
-
24If Else
If Else
Conditional statements are a part of control flow of every programming language.They work based on the following formula:
if ( condition)
{
In case it was true
}
else
{
In case it was false
}
We can nest multiple if statements within each other and we can also use “else if” as long as we know we are comparing the same condition.
For some variables such as integer, we can directly compare them using two equal signs ( == ). For others such as a NSString, we should use their built-in methods such as [myString isEqualTString: @”Some String”]
In numeric (and many other types) of comparison, we could use any of the following relational operators
<= (smaller or equal)
>= (larger or equal)
== (equal)
!= (not eqal)
&& (and)
|| (or)
! (not)
To learn more about conditional operators, you can refer to this tutorial: https://www.tutorialspoint.com/objective_c/objective_c_operators.htm
-
25Operators
Operators:
There are four general types of operators that we discussed. These four are:
Arithmetic suc as: +, -, *, /, % (modulus or remainder of a division), ++, -- (increment by one and decrement by one)
Relational such as: ==, !=, >, <, >=, <=
Logical such as: &&, ||, !
Assignment such as : =, +=, -=, *=, /=, %=
There is also a precedence between different operators which means some of them get calculated before others.
To learn more about different operators, visit this tutorial:
https://www.tutorialspoint.com/objective_c/objective_c_operators.htm
We can use ternary if statement in Objective-C such as this:
(condition) ? (statement if true) : (statement otherwise)
-
26Arrays and Sets
Arrays and Sets:
Arrays and sets are used to contain objects (usually of the same nature) inside a container.
The advantage of an array is that it has an index that ordered objects for us. The index begins at 0 and counts upwards
To use NSArray, we need to both allocate and initialize it. We will talk much further about initializing in the future. Here is an example of NSArray
NSArray* myArr = [[NSArray alloc] initWithObjects: @"Monday", @"Tuesday", @"Wednesday", nil];
We can use count to get the number of elements in an array. We can access the different elements of an array using either objectAtInde or a subscript ( [] )
NSArrays are immutable so you can not add new objects to them. For adding or removing objects into an array, we use mutable arrays.
Sets are very similar to an array except that they don't have an order. As a result the objects in a set can not be duplicates and must unique. Here is an example
NSSet* mySet = [[NSSet alloc] initWithObjects:@"one", @"two", nil];
To find objects in a set we need to iterate through them. We will discuss these for loops in more details in the future.
You could also use the C arrays. These are arrays made of any kind of object such as int such as this:
int intArray[6] = {1, 2, 3, 4, 5, 6};
Objects in an array do NOT have to be of the same type.
This is the link to the apple documentation on collection. I suggest you skim through it real quick:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Collections.html
-
27Dictionaries
Dictionaries
Dictionaries are a type of collection in Objective-C that have a key-value pairing between them.
As a result each value is paired to a certain key and can be searched and found using that key.
You can use the NSDictionary to initialize a dictionary such as:
NSDictionary *myDict = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
You would most likely be using a NSMutableDictionary such as:
NSMutableDictionary *myMutDict = [NSMutableDictionary new];
[myMutDict setObject:@"Amir" forKey:@"Name"];
To access a value for a certain key, you would be doing:
[myMutDict objectForKey:@"Name"];
You could also initialize a dictionary with multiple keys and values at once like:
NSDictionary *multipleDict = [NSDictionary dictionaryWithObjectsAndKeys: @"Value 1",@"Key1",@"Value 2",@"Key2", nil];
It's worth noticing that the keys are arbitrary values and you can use whatever you like
We can get all the keys
[myMutDict allKeys];
And we could get all the values:
[myMutDict allvalues];
You can nest arrays and dictionaries within one another.
-
28For Loops
For Loops
We use for loops for repeating a task certain number of times.
There are two main for loop formats:
A for loop based on a number
for (int i = 1; i <= 10; i++)
A for loop based on an iteration of objects
for (NSString* currentString in myArr)
-
29Occurance of X Exercise
In a given array of the names of the cities, find out how many times, does the name “Vancouver” re-occur. There is a file asset for this exercise.
-
30Compare Arrays Assignment
In this assignment, you are supposed to find the following:
Are the two arrays of the same size?
Are the objects the same?
Is the order of the objects the same?
And if the order is not the same, at what index the order breaks?
-
31Switch
Switch
Switch is another control flow command that helps with organizing the code.
It enhances the readability of the code and also it is usually mode efficient than nested if else statements.
Switch is often used with a numeric value such as integer.
You could however try and implement switch with something like a string. Switch cases can be combined as well.
-
32While Loops
While
While and Do While are two other control flow commands.
They help with running a piece of code for as long as their express is still valid.
In While we first check for the correctness of the expression. In Do While, we first do something and then check for it.
-
33Jump Statement
Jump Statement
While running a loop, it is often required to jump out of the loop or perhaps break the cycle. Jump statements help us with that.
-
34Functions
Functions
Functions are the operating parts of any object in a programming language.
An object might have some properties and some methods.
We use methods to better organize and partition our code.
Each method has a return type.
Every method may or may not have some input arguments.
-
35Dice Exercise
Write an app that runs a Dice a million times and tells you how often different numbers show up.
-
36Unique Words Assignment
Take a long string and break it into single words and find out how many of them are unique
-
37Most Photos Assignment
Find out which of the users in the given array has more photos than others
-
38Ordered Names Assignment
Sort an Array of names to appear in a Alphabetical order
-
39Available People Assignment
Sort a given array of dictionaries to be ordered based on whether the user is available or not
-
40Basic Programming Recap
-
41Basic Programming Quiz
Swift
-
42Introduction to UI
Basic User Interface
In this section, we will go back to iOS Development and using what we have learned in programming, we will begin working on a variety of basic user interface elements.
We will learn how to use UI elements as outlets and interact with them in our code. In specific in this section we will discuss topics such as:
GUI Kit
Buttons
Segmented controls
Image views
Text fields
UI switch
Sliders and steppers
View controllers
Navigation between view controllers
Passing data between different view controllers
By the end of this section, you should be easily add a variety of UI elements into your app and trigger functions in the code.
-
43GUI Kit
GUI Kit
In this lesson, we will have a look at the GUI Kit and try to familiarize ourselves with various available outlets.
These are the links to the two websites that we talked about in the video:
https://www.behance.net/gallery/54882503/iOS11-GUI-KIT
https://iosdesignkit.io/ios-gui/
-
44Buttons
Buttons
We use Buttons to trigger actions depending on when and where on them a click has landed.
We could call functions on actions directly using the assistant editor or we could use the View Controller's connection inspector to do that.
For calling actions, we could also use the addTarget method.
-
45Tap to Reveal Exercise
In this exercise, we will develop an app that when you tap a button, depending on a random generator, the name of one of the cities would appear on screen.
Scope of a variable
Variables also have a scope which means in which function (or functions) are they available.
If a declaration of a variables is inside a body of a function, that variables is said to be local to that function only.
If the declaration is outside, that variable is accessible by every function.
-
46Segmented Controls
Segmented Controls
They work like radio buttons that only one of them can be active at any given time.
The event to trigger them is the Value Changed.
Their segments are ordered from 0 upwards.
Their segments can be removed dynamically.
Their segments can be inserted dynamically.
Similar to buttons, they can be called using addTarget.
-
47Image Views
Image Views
Image Views are the containers that can show us images.
Images can be read from a variety of sources. if we use an image that is embedded into our project, we can simply use the
[UIImage imageNamed: @""]
We will see other methods of converting NS Data into images in the future.
-
48Image Switcher Exercise
Load all images into an array and depending on the button that is pressed in segmentedControl, show one of them.
-
49Text Fields
Text Fields:
In this lesson, we will learn to use basic text fields and decorate them.
We will also learn how to change the keyboard type on them and fetch values from them.
We will quickly discuss getting int values from strings as well.
We will also learn how to press a button to get rid of the keyboard.
Text Fields also have placeholders.
We should clear the text fields once they are used.
-
50UI Switch
In this lesson, we will quickly cover the mechanics of using a UI Switch outlet and changing a value (string) based on that. We will also learn about casting the sender to UI Switch.
-
51UI Slider
UI Sliders
Sliders are used to scrub between a minimum and maximum number.
Their default value is a float number.
You can set them to be triggered only when the scrub is finished and not a continuous trigger.
-
52Image Slider Exercise
We will rebuild our image switch app to switch between the images using a slider. In this example, we have to make sure, we only get the integer values from the slider
To get integers, we could either cast our float value into integers or we could use ceil, floor or round.
-
53UI Stepper
UI Stepper
Stepper are used to increment a value.
Their step can be changed.
And they can step continuously or one at a time.
Steps don't have to be integers.
-
54View Controller
View Controllers
In this lesson, we will learn how to make a new view controller and how (from interface) go through a segue
View controllers are like a container that hold on to all UI objects for a certain class and they also provide user interactivity.
-
55View Controller Class
View Controller Class
In this lesson, we will learn how to add a new view controller class and connect it to our view controller in IB
We will run a test in which a value will appear from view did load
We will discuss both classes and run cycles of view controller in future
-
56Segue
Segue
In this lesson, we will learn how to call a segue programmatically and in interface builder.
We will use the segues from buttons to view controllers.
We will also use segues from view controllers to view controllers.
We will talk further about the use of unwind segue. To use unwind segue, you would need a function with IBAction return type and an argument of the type UIStoryBoardSegue in the View Controller you are unwinding back to.
This part is a little confusing. Unwind segues are the only type of functions that you don’t code them in the class of your view controller. Rather you code them on where you want to go back to.
The difference between Unwinde and Pop is in sending data
-
57Passing Data
Passing Data Between View Controllers
In this lesson, we will learn how to prepare for a segue and pass data between our different view controller
To do that, we need to prepare for an upcoming segue using the prepareForSegue built-in function
-
58Recap
Recap
In this section, we covered the following topics:
Buttons and how to assign functions to them in the storyboard as well as using the addTarget.
Segmented controls and how their selectedIndex number helps us
Image Views and how we could load images into them and change the content mode.
Text Fields and how we could change keyboard on them.
Switch and how we could get their isOn state.
Sliders and how we could read their value.
Steppers and how we could use them to increment or decrement a value.
View controllers and how we could use them to categorize our app also assign separate view controller classes to them.
We finally touched on segues and passing data between view controllers using prepareForSegue
-
59Find Image Assignment
In this assignment, using the images and the dictionary provided, you have to write an app, where a user can enter name in the text field and if they exist in our “database”, their image should appear on the screen. Otherwise a warning should tell us that there is no such user.
-
60User Manager Assignment
In this assignment, you would write an app with two view controllers, in one of them we can enter details about a user such as their name, height, city where they live, etc. In the other view controller, we should be able to view the details of all of our users.
As a bonus, you can expand this app into making sure, we can search for a specific user by the name.
-
61Basic User Interface Recap
-
62Basic User interface Quiz
Further Programming
-
63Introduction to Swift Section
In this section, we talked about Swift and got started with actually coding in Swift. In particular we covered the following basic matters:
Swift Basics
Swift Playground
Swift Strings
Collections in Swift (Arrays and Dictionaries)
Functions in Swift
-
64Playground
Playground is the learning environment of XCode for Swift. You could use it on both your Mac as well as on your iPad.
-
65Swift Variables
Next important topic is the variable in Swift. We have several different matters to keep in mind:
Let for introducing immutable variables. Let example is Objective-C is NSArray
Var for introducing mutable variables. Var example is Objective-C is NSMutableArray
Type Annotations
In Swift, we could use the type annotations to explicitly define the type of a variable.
Writing comments are similar to those in objective-C
Semicolons are not necessary in Swift.
String Interpolation print ("(myFloat)")
-
66Swift Optionals
Swift optional are a rather important topic. If a variable is optional, it can be nil. Otherwise it must have a value.
var optionalString: String? // which can be nil
var nonOptionalString: String = "Hello" // Which Must have a value
var unWrappedString: String! // implicitly unwrapped optional. Implicitly unwrapped optional are useful when an optional value is confirmed to exist. ! lets you treat the property as if it were non-optional
You can do force unwrapping by ! . It's not the safest thing to do though
var n : Int?
print ("(n!)")
Conditional Unwrapping
var someVar : Int?
if let val = someVar // you can also use the same name
{
print ("(val)")
}
else
{
print ("nada");
}
Type casting for unwrapping
var someVal: Any? = 1
if someVal as? String != nil {
print("This is string")
}
if someVal as? Int != nil {
print("Int's Int")
}
Link for further study: https://docs.swift.org/swift-book/LanguageGuide/OptionalChaining.html
-
67Swift Control Flow
If Else
In an If Statement, we don't need the round brackets, but the curly brackets for the statement are necessary
If n == true {
}
Switch
The break statement inside a switch can be used when you don't need a case to have any actual functionality.
for
In a for loop, you shouldn't use round brackets and the numbering is different. For in example
for any in "Ding"
{
print ("(any)")
}
Repeat While and While are exactly identical to Do While and While
-
68Swift Strings
let someString = "Some string literal value"
let multilineString = """
These are the same.
"""
var variableString = "Horse"
variableString += " and carriage"
if quotation == sameQuotation {
print("These two strings are considered equal")
}
Read further at:
https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html
-
69Arrays in Swift
Arrays in swift are rather simplified
var myArray : Array <String> = ["Hello", "World", "Swift", "iOS"]
print ("(myArray)")
myArray.remove(at: 1)
print ("(myArray)")
myArray.append("ObjC")
print ("(myArray)")
You can use Any for arras where the type is not predetermined
var myArray : Array <String> = ["Hello", "World", "Swift", "iOS"]
if let index = myArray.index(of: "Hello") {
print("Found Hello at index (index)")
}
You can still use the NSArray if you prefer, but you cannot explicitly select its type
var myNsArr : NSMutableArray = NSMutableArray.init(objects: "Hi", "World");
myNsArr.index(of: "Hi")
-
70Dictionaries in Swift
Dictionaries in Swift are rather simplified and powerful. We declare dictionaries by a var or let of the type dictionary and then we can explicitly mention the type of the values in that dictionary.
We could also let the types be inferred from the values.
Once we have a dictionary, we can add new key-value pairs to it or update them.
For iterating within a dictionary, we rely on tuples. Tuples are a powerful ordered set of values. The values can be accessed by index or by name.
var person = ("John", "Smith")
var firstName = person.0 // John
var lastName = person.1 // Smith
var person2 = (firstName: "John", lastName: "Smith")
var firstName = person2.firstName // John
var lastName = person.1 // Smith
var namesOfIntegers = [Int: String]()
namesOfIntegers[16] = "sixteen"
var airports: [String: String] = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
Or
var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
airports["LHR"] = "London"
for (airportCode, airportName) in airports
{
print("(airportCode): (airportName)")
}
-
71Functions in Swift
Swift functions are written in a slightly different format than that of Objective-C.
func myFunc (inp: String) -> (name: String, res: Int)
{
return ("Hello " + inp, 2)
}
myFunc (inp: "Amir")
We can also nest functions inside one another
func nestedFunc ()
{
func internalFunc () -> String
{
return "yo"
}
print ( internalFunc() )
}
nestedFunc()
-
72Swift in iOS
From this point on, we should get used to both of them
In this lesson, we will go through a sample app in iOS with Swift.
We no longer have a .h and .m file. Everything is in one place
-
73Random Image Picker Exercise
This app, will load a new random image based on the click of the button, It will not re-show any image. Only new unique ones. Once we expire all images, it’ll restart the images
-
74Swift User Manager Assignment
In this assignment, you will re-write the User Manager app from the previous section. This time in Swift
-
75Swift Recap
-
76Swift Quiz