Swift Terms Flashcards
parameters
optional input values that exist between the ( ) in a function definition
parameter rules
- If a parameter exists, an argument must be passed in when the function is called or the compiler will throw an error
- The argument must be the same type of value that the parameter is declared to have
- When referencing a function, include the parameter name(s) in its title followed by a colon such as findGardenArea(side:)
tuple
Group together values that are enclosed in parentheses separated by commas
implicit return
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
Default Parameter
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) }
Variadic Parameter
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 }
Optional type
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.
!
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.
what does the .keys property do?
stores a collection of dictionary keys
what does the .values property do?
stores a collection of dictionary values.
what is a dictionary in Swift?
An unordered collection of key-value pairs
what is a class?
A template to create objects.
The term “object” is often used to refer to an _____ of a class
instance
What is the difference between a class and a structure?
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.
What is method overriding?
When a subclass provides its own custom implementation of a property or method that is inherited from a superclass.
Structures are ____ types but Classes are ____ types
value, reference
What is a value type?
A type whose value is copied when it’s assigned to a variable or constant, or when it’s passed to a function.
What are the basic value types in Swift?
Int, Double, Bool, String, Arrays, Dictionaries
How do value types differ from reference types?
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.
When using structs and classes always use ___ to start, and change it to ___ if _____ is needed or use class instances for their reference typing.
struct, class, inheritance
what does using the init() method allow us to do?
provide an instance with specific values right off-the-bat during the creation of an instance.
What will happen to a copied class that has it’s properties altered?
It will affect the original class from which it was copied.
in-out Parameter
A parameter whose value is passed into a function and modified within the body
What are structures
A means of modeling real life objects programmatically
Void
means that it does not return any value when used to specify return type in a function. The first letter (V) is capitalized
Unary Operator
Indicates that a value is negative rather than positive, aka the "negative operator" EX. var x = -10