Section 1

Preview this deck

Adding Protocol Conformance with an Extension

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (142)

Section 1

(50 cards)

Adding Protocol Conformance with an Extension

Front

extending an existing type to adopt and conform to a new protocol, even if you do not have access to the source code for the existing type.

Back

protocol inheritance

Front

A protocol can inherit one or more other protocols and can add further requirements on top of the requirements it inherits

Back

subclass initializer first step

Front

Setting the value of properties that the subclass declares.

Back

what do classes, structures and enumerations can have

Front

properties and methods

Back

optional protocol requirements

Front

These requirements do not have to be implemented by types that conform to the protocol.

Back

subclass initializer third step

Front

Changing the value of properties defined by the superclass

Back

difference between class and structure/enumeration

Front

class is reference type, structure and enumeration are value types

Back

Initializer Chaining Rule 3

Front

Convenience initializers must ultimately end up calling a designated initializer.

Back

type parameter

Front

specify and name a placeholder type, and are written immediately after the function's name, between a pair of matching angle brackets (such as <T>).

Back

type constraint

Front

used to enforce certain type constraints on the types that can be used with generic functions and generic types.

Back

optional chaining syntax

Front

var test: int? test?.incr() returns nil test!.incr() throws exception

Back

constant stored property

Front

defined by let

Back

designated initializer syntax

Front

init(parameters){statements}

Back

Protocol Composition syntax

Front

protocol<SomeProtocol, AnotherProtocol> this is a type.

Back

subscripts

Front

accessing elements of list, collections and arrays by index

Back

Initializer Chaining Rule 2

Front

Convenience initializers must call another initializer available in the same class

Back

Protocol Composition

Front

combining multiple protocols into a single requirement with a protocol composition.

Back

optional protocol syntax

Front

„@optional func incrementForCount(count: Int) -> Int

Back

Automatic Initializer Inheritance Rule 1

Front

If your subclass doesn't define any designated initializers, it automatically inherits all of its superclass designated initializers.

Back

keys and values of dictionaries copied by value or by reference

Front

if key or value is value type then copied by value else copied by reference

Back

convenient initializer syntax

Front

convenience init(parameters){statements}

Back

generic type

Front

type with type parameter

Back

generics

Front

enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define

Back

backing store

Front

stored properties have no backing store

Back

Initializer Chaining Rule 1

Front

Designated initializers must call a designated initializer from their immediate superclass.

Back

protocol

Front

A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality.

Back

Initializer delegation

Front

Designated initializers must always delegate up. Convenience initializers must always delegate across.

Back

Two-Phase Initialization Second Step

Front

each class is given the opportunity to customize its stored properties further

Back

can constant properties be modified

Front

no, only during initialization

Back

external parameter name

Front

only visible to calling function

Back

dictionaries and arrays class or structure

Front

dictionaries and arrays are structures (value types)

Back

how is delegation implemented

Front

by defining a protocol that encapsulates the delegated responsibilities, such that a conforming type (known as a delegate) is guaranteed to provide the functionality that has been delegated

Back

Automatic Initializer Inheritance Rule 2

Front

If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.

Back

property observers can only be defined for which property type ?

Front

stored property (not computed property)

Back

lazy stored property

Front

defined by @lazy var varName = value initialized only when first accessed

Back

Designated initializer

Front

primary initializer for a class

Back

Initializer Inheritance

Front

subclasses do not not inherit their superclass initializers by default

Back

optional chaining

Front

process for querying and calling properties, methods, and subscripts on an optional that might currently be nil

Back

subclass initializer second step

Front

Calling the superclass's initializer.

Back

Two-Phase Initialization First Step

Front

each stored property is assigned an initial value by the class that introduced it

Back

generic function

Front

function with type parameter

Back

what element has a raw values, member values and associated values

Front

enumerations

Back

delegation

Front

design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type

Back

which type of properties can have getters and setters

Front

computed properties

Back

property observer

Front

observe and respond to changes in a property's value

Back

variable stored property

Front

defined by var

Back

Initialization

Front

process of preparing an instance of a class, structure, or enumeration for use

Back

willSet and didSet called in initialization ?

Front

no not called in initialization

Back

local parameter name

Front

only visible in method or function definition

Back

Convenience initializers

Front

secondary, supporting initializers for a class

Back

Section 2

(50 cards)

optional an if

Front

You can use an if statement to find out whether an optional contains a value. If an optional does have a value, it evaluates to true; if it has no value at all, it evaluates to false

Back

inout parameters

Front

func swapTwoInts(inout a: Int, inout b: Int) { let temporaryA = a a = b b = temporaryA } var someInt = 3 var anotherInt = 107 swapTwoInts(&someInt, &anotherInt)

Back

string value or reference type

Front

value type

Back

optional binding sample

Front

if let actualNumber = possibleNumber.toInt() { println("\(possibleNumber) has an integer value of \(actualNumber)") } else { println("\(possibleNumber) could not be converted to an integer") }

Back

tuple naming individual elements

Front

let http200Status = (statusCode: 200, description: "OK")

Back

++i or i++ best practice

Front

++i is recommended if specific behavior of i++ is not needed.

Back

numeric type conversion

Front

let twoThousand: UInt16 = 2_000 let one: UInt8 = 1 let twoThousandAndOne = twoThousand + UInt16(one)

Back

nested function

Front

define functions inside the bodies of other functions

Back

labeled statements

Front

You can nest loops and switch statements inside other loops and switch statements in Swift to create complex control flow structures. It is sometimes useful to be explicit about which loop or switch statement you want a break statement to terminate. break gameLoop

Back

switch where clause

Front

A switch case can use a where clause to check for additional conditions

Back

tuple decomposing

Front

let http404Error = (404, "Not Found") let (statusCode, statusMessage) = http404Error or by index println("The status code is \(http404Error.0)")

Back

identity operators

Front

=== and !== to test whether two object references both refer to the same object instance

Back

function definition

Front

func halfOpenRangeLength(start: Int, end: Int) -> Int { return end - start }

Back

switch tuple matching

Front

case (1,2): case(1, _) _ any possible value

Back

optional

Front

An optional says: There is a value, and it equals x or There isn't a value at all

Back

tuple sample

Front

(404, "Not Found")

Back

optional binding

Front

find out whether an optional contains a value, and if so, to make that value available as a temporary constant or variable

Back

shorthand external parameter name

Front

used for both: internal and external parameter name # func containsCharacter(#string: String, #characterToFind: Character) -> Bool { for character in string { if character == characterToFind { return true } } return false }

Back

closed range operator

Front

... z.B. for index in 1...4

Back

return value for no return value

Front

empty tuple: ()

Back

assertions

Front

An assertion is a runtime check that a logical condition definitely evaluates to true

Back

type alias

Front

typealias AudioSample = UInt16

Back

type cast operator

Front

as, as? as? returns optional form of type

Back

switch range matching

Front

case 1...3:

Back

optional binding syntax

Front

if let constantName = someOptional { statements }

Back

logical and &&

Front

with short circuit

Back

half-closed range operator

Front

a..b for i in 0..names.count

Back

switch where syntax

Front

case let (x, y) where x == y: example is tuple matching

Back

no void keyword

Front

func sayGoodbye(personName: String) { println("Goodbye, \(personName)!") }

Back

function tpye 2

Front

func printHelloWorld() { println("hello, world") } () -> ()

Back

mutable string

Front

assign string to variable: var s = "string"

Back

implicitly unwrapped optional

Front

You can think of an implicitly unwrapped optional as giving permission for the optional to be unwrapped automatically whenever it is used

Back

implicitly unwrapped optional sample

Front

let assumedString: String! = "An implicitly unwrapped optional string." println(assumedString)

Back

forced unwrapping sample

Front

if convertedNumber { println("\(possibleNumber) has an integer value of \(convertedNumber!)") } else { println("\(possibleNumber) could not be converted to an integer") }

Back

switch value binding syntax

Front

case (0, let y): remark: this is tuple matching

Back

exhaustive switch

Front

every switch statement must be exhaustive use default catch-all case

Back

assertion sample

Front

let age = -3 assert(age >= 0, "A person's age cannot be less than zero")

Back

variable parameter

Front

can be changed inside function but change is not visible outside of function

Back

forced unwrapping

Front

I know that this optional definitely has a value; please use it

Back

function type

Front

func addTwoInts(a: Int, b: Int) -> Int { return a + b } func multiplyTwoInts(a: Int, b: Int) -> Int { return a * b } (Int, Int) -> Int

Back

function type 3

Front

var mathFunction: (Int, Int) -> Int = addTwoInts

Back

variadic parameters

Front

defined by ... after type of parameter func arithmeticMean(numbers: Double...) -> Double { var total: Double = 0 for number in numbers { total += number } return total / Double(numbers.count) }

Back

string interpolation

Front

insert constants, variables, literals, and expressions into longer strings

Back

max Int number

Front

Int.max

Back

tuple

Front

group multiple values into a single compound value

Back

type check operator

Front

is

Back

logical or ||

Front

with short circuit

Back

literal

Front

a value that appears directly in the source code

Back

switch value bindings

Front

can bind the value or values it matches to temporary constants or variables, for use in the body of the case

Back

closed range operator

Front

a...b for index in 1...5

Back

Section 3

(42 cards)

closure expression syntax

Front

{ (parameters) -> return type in statements }

Back

Global functions

Front

are closures that have a name and do not capture any values

Back

adding arrays

Front

var sixDoubles = threeDoubles + anotherThreeDoubles

Back

functions and closures

Front

Functions are actually special cases of closures

Back

trailing closure

Front

closure can be written outside of the sort function's parentheses: reversed = sort(names) { $0 > $1 }

Back

which property type can be added by an extension

Front

only computed property, not stored property

Back

array literal

Front

var shoppingList: [String] = ["Eggs", "Milk"]

Back

retroactive modeling

Front

the ability to extend types for which you do not have access to the original source code

Back

nested type

Front

nest supporting enumerations, classes, and structures within the definition of the type they support.

Back

subscript syntax returns optional

Front

if let airportName = airports["DUB"] { println("The name of the airport is \(airportName).") } else { println("That airport is not in the airports dictionary.") }

Back

Nested functions

Front

closures that have a name and can capture values from their enclosing function

Back

Inferring Type of closure from context

Front

input types and return type can be omitted: reversed = sort(names, { s1, s2 in return s1 > s2 } )

Back

Extension Syntax

Front

extension SomeType { // new functionality to add to SomeType goes here }

Back

empty dictionnary

Front

namesOfIntegers[16] = "sixteen" // namesOfIntegers now contains 1 key-value pair namesOfIntegers = [:] now it is empty

Back

Closure expressions

Front

unnamed closures written in a lightweight syntax that can capture values from their surrounding context

Back

closure expression sample

Front

reversed = sort(names, { (s1: String, s2: String) -> Bool in return s1 > s2 })

Back

dictionnary initialization

Front

var namesOfIntegers = [Int: String]()

Back

weak reference

Front

a reference that does not keep a strong hold on the instance it refers to, and so does not stop ARC from disposing of the referenced instance

Back

unowned reference

Front

Like weak references, an unowned reference does not keep a strong hold on the instance it refers to. Unlike a weak reference, however, an unowned reference is assumed to always have a value

Back

capture by reference

Front

when variable is modified, reference of value is captured so that it is available when the closure is called next time

Back

mutability of collections

Front

If you create an array or a dictionary and assign it to a variable, the collection that is created will be mutable. If assigned to constant it is immutable.

Back

dictionnaire literal syntax

Front

var airports: [String: String] = ["TYO": "Tokyo", "DUB": "Dublin"]

Back

Accessing and Modifying an Array

Front

shoppingList.count shoppingList.isEmpty shoppingList.append("Flour") shoppingList += "Baking Powder" shoppingList += ["Chocolate Spread", "Cheese", "Butter"] var firstItem = shoppingList[0] shoppingList[4...6] = ["Bananas", "Apples"] shoppingList.insert("Maple Syrup", atIndex: 0) let mapleSyrup = shoppingList.removeAtIndex(0) let apples = shoppingList.removeLast()

Back

array initialization part 2

Front

var threeDoubles = [Double](count: 3, repeatedValue: 0.0)

Back

Accessing and Modifying a Dictionary

Front

airports.count airports["LHR"] = "London"

Back

remove item from dictionary

Front

if let removedValue = airports.removeValueForKey("DUB") { println("The removed airport's name is \(removedValue).") } else { println("The airports dictionary does not contain a value for DUB.") }

Back

closing

Front

Closures can capture and store references to any constants and variables from the context in which they are defined

Back

array initialization

Front

var someInts = [Int]() someInts is of Type [Int]

Back

which initializer type can be added by an extension

Front

only convenience initializers, not designated initializers

Back

closure

Front

self-contained blocks of functionality that can be passed around and used in your code

Back

Operator Functions

Front

> is an operator function of type (s1: String, s2: String) -> Bool and can be used as closure: reversed = sort(names, >)

Back

updateValue

Front

if let oldValue = airports.updateValue("Dublin International", forKey: "DUB") { println("The old value for DUB was \(oldValue).") }

Back

capturing values

Front

A closure can capture constants and variables from the surrounding context in which it is defined. The closure can then refer to and modify the values of those constants and variables from within its body, even if the original scope that defined the constants and variables no longer exists.

Back

closures reference or value types

Front

closures (and functions) are reference types

Back

mix and match

Front

write apps that have a mixed-language codebase: Swift and Objective-C

Back

implicit Returns from Single-Expression Closures

Front

return keyword can be omitted: reversed = sort(names, { s1, s2 in s1 > s2 } )

Back

dictionnaire type shorthand syntax

Front

Dictionary<KeyType, ValueType> can be written as [KeyType: ValueType]

Back

Shorthand Argument Names

Front

closure's argument list + keyword in can be omitted: reversed = sort(names, { $0 > $1 } )

Back

array type shorthand syntax

Front

Array<SomeType> can be written as [SomeType]

Back

iterate over dictionnary

Front

for (airportCode, airportName) in airports { println("\(airportCode): \(airportName)") } iterate by tuple

Back

empty array

Front

someInts = [] if someInts is of known type, it is emptied

Back

capture by copy

Front

when variable is not modified, copy of value is captured

Back