Code – Part 4 Adding an item to an Array | Swift Programming Series

Download the file here: Tutorial.playground

Watch the full video here: https://youtu.be/8JK7vbLi_eU


Read the code below:

// Variables & Constants

let firstName = "Ben" // Constant

let lastName = "Tennyson"

let fullName = firstName + " " + lastName // String Concatenation

let interpolatedFullName = "My friend's name is \(firstName) \(lastName)" // String Interpolation

print(interpolatedFullName)

print(fullName)

var age = 16 // Variable

print("\(firstName) is \(age) years old!")

// Gives Error!! print(firstName + " is " + age + " years old!")

var profession = "Student"

print("\(fullName) is a \(age) year old \(profession)!")

// ------------------------------

// Collection Types

// 1. Arrays

// 2. Dictionaries

// 3. Sets

// Arrays

// let example = [9, 100, 81, 23]

var todo: [String] = ["Complete Homework", "Buy a Notebook", "Record Swift Tutorial"]

todo[0]

print(todo[1])

var friendList: [String] = ["John", "Joe"]

// First method to add item to an Array

friendList.append("Steve")

friendList

friendList[2]

// Second method to add item to an Array

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: