Swift Terms Flashcards

1
Q

parameters

A

optional input values that exist between the ( ) in a function definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

parameter rules

A
  1. If a parameter exists, an argument must be passed in when the function is called or the compiler will throw an error
  2. The argument must be the same type of value that the parameter is declared to have
  3. When referencing a function, include the parameter name(s) in its title followed by a colon such as findGardenArea(side:)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

tuple

A

Group together values that are enclosed in parentheses separated by commas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

implicit return

A

If there is only a single expression or value in the body, you can omit the return keyword and still have your function return a value - used to shorten code within the function body but not mandatory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Default Parameter

A
A parameter that has a default value does not require an argument passed into it then the function is called. example
func totalWithTip(total: Double, tip: Double = 0.2) -> Double {
 return total + (total * tip)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Variadic Parameter

A
Accepts zero or more values of a certain type. Useful when you might need to pass in more than one value for a single parameter example
func functionName(paramName: paramType...) -> returnType {
  // function's task goes here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Optional type

A

A type that represents either a wrapped value or nil, the absence of a value, optional is used in Swift when a value may not exist.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

!

A

forces the compiler to unwrap an optional value and interpret the value as its appropriate data type, errors can occur using ! if value does not exist.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does the .keys property do?

A

stores a collection of dictionary keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does the .values property do?

A

stores a collection of dictionary values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a dictionary in Swift?

A

An unordered collection of key-value pairs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is a class?

A

A template to create objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The term “object” is often used to refer to an _____ of a class

A

instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between a class and a structure?

A

When we define a class, it can inherit, or take on, another class’s properties and methods. Structures do not offer this capability. Moreover inheritance is a fundamental behavior that differentiates classes from other types in Swift.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is method overriding?

A

When a subclass provides its own custom implementation of a property or method that is inherited from a superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Structures are ____ types but Classes are ____ types

A

value, reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a value type?

A

A type whose value is copied when it’s assigned to a variable or constant, or when it’s passed to a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the basic value types in Swift?

A

Int, Double, Bool, String, Arrays, Dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do value types differ from reference types?

A

Reference types are not copied when they are assigned to a variable or constant, or when they are passed to a function. Instead a reference to the same existing instance is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

When using structs and classes always use ___ to start, and change it to ___ if _____ is needed or use class instances for their reference typing.

A

struct, class, inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what does using the init() method allow us to do?

A

provide an instance with specific values right off-the-bat during the creation of an instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What will happen to a copied class that has it’s properties altered?

A

It will affect the original class from which it was copied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

in-out Parameter

A

A parameter whose value is passed into a function and modified within the body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are structures

A

A means of modeling real life objects programmatically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Void

A

means that it does not return any value when used to specify return type in a function. The first letter (V) is capitalized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Unary Operator

A
Indicates that a value is negative rather than positive, aka the "negative operator"
EX. var x = -10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

binary operator

A

An operator that takes in two operands

EX. x = x - 5 // Subtraction operator. Subtracts 5 from x

28
Q

NOT operator

A

!

29
Q

AND operator

A

&&

30
Q

OR operator

A

||

31
Q

Nil Coalescing Operator

A

?> allows a default value to be used in the event that an optional has a nil value.

32
Q

What are “loops”?

A

Sequences of Swift statements which are to be executed repeatedly until a specified condition is met.

33
Q

That is the “for-in” loop used for?

A

To iterate over a sequence of items contained in a collection or number range and provides a simple to use looping option.

34
Q

What does the swift “while loop” do?

A

Repeats a set of tasks while a specified condition is met.

EX. while { //Swift statements go here }

35
Q

What is a condition?

A

An expression that will return either true or false.

36
Q
  1. What is the repeat .. while loop provided for? 2. what does it replace?
A
  1. It is provided for situations where you know that the code contained in the body of the loop will always need to be executed at least once. 2. It replaces the Swift 1.x do .. while loop.
37
Q

What is a situation where you may want to use a “repeat … while loop”?

A

You may want to keep stepping through the items in an array until a specific item is found.

38
Q

What does a “break” statement do?

A

breaks out of the current loop and resumes execution at the code directly after the loop.

39
Q

What does a “Continue” statement do?

A

Causes all remaining code statements in a loop to be skipped, and execution to be returned to the top of the loop.

40
Q

What does a “guard” statement do?

A

Contains a boolean expression which must evaluate to true in order for the code located after the guard statement to be executed.

41
Q

The guard statement must include an ________ to be executed in the event that the expression evaluates to false. The code in the else clause must contain a ______ to exit the current code flow.

A

else clause, statement (i.e return, break, continue, throw)

42
Q

What is a swift “switch” statement good for?

A

For a small number of logical evaluations of a value the if…else if … construct is perfectly adequate. Unfortunately, any more than two or three possible scenarios can quickly make such a construct both time consuming to write and difficult to read. For such situations, the “switch” statement provides an excellent alternative.

43
Q

Where did swift inherit the switch statement from?

A

The C programming language

44
Q

Use case for a “fallthrough” statement?

A

The fallthrough effect of other switch implementations in languages such as objective c whereby the execution path continues through the remaining case statements can be emulated using the “fallthrough” statement.

45
Q

When is a break statement useful in a Swift switch statement

A
When no action needs to be taken for the default case
EX. 
defualt:
        break
}
46
Q

What is a function?

A

A named block of code that can be called upon to perform a specific task.

47
Q

What is a method?

A

A function that is associated with a particular class, structure or enumeration.

48
Q

Assignment operator?

A

=

49
Q

What are local parameter names?

A

Parameters that can be referenced within the body of the function code by name.

50
Q

What are external parameter names?

A

Names by which the parameter is referenced when the function is called

51
Q

How can you remove default external parameter names?

A
By preceding the local parameter names with an underscore ( _ ) character as follows:
func buildMessageFor (_ name: String, _ count: Int ) -> String { 
return ( " \ (name), you are customer number \ (count) " )
}
52
Q

What are closure expressions?

A

Self-contained blocks of code

53
Q

What are “shorthand argument names”?

A

A useful technique for simplifying closures involves using shorthand argument names. This allows the parameter names and “in” keyword to be omitted from the declaration and the arguments to be references as $0, $1, $2 etc.

54
Q

Define Functions, closures, and closure expressions in one sentence.

A

Self-contained blocks of code that can be called upon to perform a specific task and provide a mechanism for structuring code and promoting reuse.

55
Q

What is an instance?

A

Instances consist of data variables (called properties) and functions (called methods) that can be accessed and called on the instance to perform tasks and are collectively referred to as class members.

56
Q

What does a class do?

A

A class defines what an instance will look like when it is created.

57
Q

With regards to a class what are “Properties”?

A

The properties section of the declaration defines the variables and constants that are to be contained within the class.

58
Q

As it relates to a class what are “Instance methods” and “Type methods”?

A

The instance methods and type methods sections define the methods that are available to be called on the class and instances of the class.

59
Q

Array count property

A
A count of the items in an array can be obtained by accessing the array's count property
var newVar = arrName.count
60
Q

Array isEmpty property

A
Whether or not an array is empty can be identified using the array's Boolean isEmpty property
if arrName.isEmpty {
 // Array is empty
}
61
Q

What is “index subscripting”?

A

A specific item in an array may be accessed of modified by referencing the item’s position in the array index (where the first item in the array has index position 0) using a technique referred to as “index subscripting”.
EX: treeArray[1] = “Redwood”
The above code replaces the current value at index position 1 with a new String value that reads “Redwood”

62
Q

Explain the “shuffled( )” method of an array object?

A
A call to the shuffled( ) method of an array object will return a new version of the array with the item ordering randomly shuffled, ex:
let oldArrName = newArrName.shuffled( )
63
Q

Explain the “randomElement( )” method?

A
To access an array item at random, simply make a call to the randomElement( ) method EX:
let randomTree = treeArray.randomElement( )
64
Q

What is a “Mixed Type” array?

A

A mixed type array is an array that can contain elements of different class types.

65
Q

What is “Any”?

A

“Any” is a special type in Swift that can be used to reference an object of a non-specific class type.