Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1. Tuples enable you to create and pass around groupings of values.

You can use a tuple to return multiple values from a function as a single
compound value.

2. You declare constants with the let keyword and variables with the var
keyword.

3.Swift is a type-safe language, which


means the language helps you to be clear about the types of values your code
can work with.

4. You can declare multiple constants or multiple variables on a single line,


separated by commas:

var x = 0.0, y = 0.0, z = 0.0

Type Annotations(of type ,to be clear about the kind of values the constant or
variable can store.)

1. by placing a colon after the constant or variable name, followed by a


space, followed by the name of the type to use. Example var
welcomeMessage: String
2. var red, green, blue: Double
3. If you provide an initial value for a constant or variable at the point that it
is defined, Swift can almost always infer the type to be used for that
constant or variable(type inference)

Naming Constants and Variables


1. Constant and variable names can contain almost any character, including Unicode characters:

1. let = 3.14159
2. let = ""
3. let = "dogcow"

2. Once youve declared a constant or variable of a certain type, you cant


redeclare it again

3. If you need to give a constant or variable the same name as a reserved Swift
keyword, surround the keyword with backticks (`)

Printing Constants and Variables

1. print the current value of a constant or variable with the


print(_:separator:terminator:) function
2. prints its output in Xcodes console pane.
3. To print a value without a line break after it, pass an empty string as the
terminatorfor example, print(someValue, terminator: "").

4. String interpolation : print("The current value of friendlyWelcome is \(friendlyWelcome)")

// Prints "The current value of friendlyWelcome is Bonjour!"

Semicolons
semicolons are required if you want to write multiple separate statements on a single line:

1. let cat = ""; print(cat)

Type Safety and Type Inference

1. Swift always chooses Double (rather than Float) when inferring the type of
floating-point numbers

Collection Types

1. arrays, sets, and dictionaries


2.

Closures

1. self-contained blocks of functionality that can be passed around and used


in your code
2. can capture and store references to any constants and variables from the
context in which they are defined
3.

You might also like