Section 1

Preview this deck

how do you stop "unused result" warnings?

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 (39)

Section 1

(39 cards)

how do you stop "unused result" warnings?

Front

@discardableResult on the line above the function

Back

two scopes in swift?

Front

top-level or global/local or nested

Back

what is object shadowing?

Front

when we declare an object at a lower level of scope with the same name as a higher level of scope object.

Back

how do you save a value to user defaults?

Front

UserDefaults.standard.set(Bool, forKey: "darkMode") where standard is an instance of userDefaults

Back

struct is _____ type and class is ________ type

Front

value, reference

Back

what is the default scope for variables, constants, and other named declarations?

Front

top-level or global, only works if declared at the base of a .swift file. Inside any {} the scope is changed to that function level

Back

what are the two generic types of a keyPath?

Front

Root, Value keyPath<Root, Value> the root is the thing, the instance of something while the value is just that

Back

difference between a class and struct default initializer?

Front

classes receive a default init (){} while a struct gets a memberwise init meaning each variable is just placed in the conditions. init(x:Int, y:String)

Back

what is the cleanest way to implement selectors?

Front

extension Selector { static let functionName = #selector(functionName(_: )) } this lets you call .functionName as your selector make it filePrivate to be available only in your class

Back

2 requirements of using optionals with protocols?

Front

they only work with classes and you have to expose the objective c runtime. this also means you limit swift functionality meaning swift features may not be available. Eg. you cant pass structs/enums to a protocol, you cant make your optional function extended

Back

3 primary tools of core data stack?

Front

Managed Object Model Persistent Store Coordinator Managed Object Context

Back

library needed to support os_log?

Front

import os

Back

define continue statement

Front

tells a loop to stop what its doing and start at the beginning

Back

Starting in swift 5 what is a faster way of doing stings full of special characters such as Json?

Front

Raw strings, disables all special characters #"insert text here"#

Back

syntax of guard statement

Front

guard (condition) else {}

Back

what are the 5 log levels in os_log?

Front

default-stores in mem, writes to disk periordically error-always stores to disk, something wrong in your app fault-always stores to disk, something wrong in the system info- meant for capturing background info, will store to disk if a fault log is tripped debug- not for production

Back

how do we pass generic types into a function?

Front

func Name<genericType>(params: genericType, params2: genericType) {} often with generic types is customary to use only 1 capital letter like T, P, Q whatever you like

Back

where do we write functions in a protocol?

Front

you have to write the func signature in the protocol definition but then use an extension to write the implementation

Back

define break statement

Front

ends executing of entire control flow statement. When used inside of a switch or loop ends that statement before it otherwise would end

Back

how to add namespace to os_log?

Front

import os private let subsystem = "com.daviddailey.ALSA_Brevity_Guide" struct Log { static let table = OSLog(subsystem: subsystem, category: "table") }

Back

define fallthrough statement

Front

gives C style fallthrough where after matching to a switch case the expression continues instead of exiting the switch

Back

what is self?

Front

refers to current class instance from within the class instance

Back

4 levels of swift code organization

Front

modules-source files-classes-code blocks(also called methods when associated with a class)

Back

what is target action in swift?

Front

you're sending a message, the action, to an object, the target there is always an action (think selector(function)) that gets called on an object (think target(class/object))

Back

switch statement syntax?

Front

switch (value to consider) { case value1: do something case value2, value3: do something else default: always have a default switch stops working as soon as a case matches. no break or return is needed

Back

how does adding code implementation in an extension effect a protocol?

Front

it allows default functionality which can still be implemented inside your objects which conform. no need to override

Back

syntax for os_log?

Front

os_log("statement %d", log: OSLog, type: .log_level, dynamicValue) where %d allows a dynamic value instead of string interpolation

Back

possible else statements for guard? 4

Front

return, break, continue, throw

Back

what does a guard statement do?

Front

transfers program control out of scope if one or more conditions aren't met. created object can be used for the rest of scope

Back

what design pattern does notification center use?

Front

observer-observable

Back

structure for Log.swift file?

Front

import os private let subsystem = "com.razeware.Chirper" struct Log { static let table = OSLog(subsystem: subsystem, category: "table") }

Back

string interpolation with raw strings?

Front

\#(string here)

Back

difference between value type(struct and enum) vs classes with initializer inheritance?

Front

value types do not support inheritance, while classes must take into account all higher level init functions to ensure all stored properties are assigned a value during init

Back

what is a selector in swift? What is its syntax?

Front

its used to describe the name of a function, #selector(functionToExecute(_: )) where (_: ) just matches the overloads within your function, think of it as a generic func also you must expose your function you want to use to objc with @objc

Back

syntax for adding an observer in notification center?

Front

addObserver(_, selector:, name:, object:) _ : usually self, this is the 'target' also called observer selector: function to be called when action observed name: notification you're listening for Notification.Name object: optional object to listen to only one source

Back

when using mutating func in protocols when do we have to use the mutating keyword in objects that conform?

Front

in value type objects(eg struct) but not in inheritance type objects(eg class)

Back

make a collection of all enum types?

Front

set the enum's class to CaseIterateable, then access the collections via enum.allCases

Back

syntax for os_signpost?

Front

os_signpost(_ type: typeOfCall, log: OSLog, name: "whatever you want", signpostID: SignpostID, "message to be logged %@", place to put %value)

Back

How do you retrieve a user default?

Front

var darkMode = UserDefaults.standard.bool(forKey: "darkMode") false returns as default

Back