Swift Flashcards

1
Q

python: To read a txt file into python, type

A

file = open(“/words.txt”, “r”)
words = file.read()
file.close()

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

python: To turn a list of words into a dict with the keys being the unique words and the values being their frequency in the list, type

A

from collections import Counter

counts = Counter(my_word_list)

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

swift: UIkit stands for

A

User Interface Kit

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

swift: var variableName only needs to be used

A

upon instantiation.

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

swift variable names should be written in

A

camelcase

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

swift: A constant is

A

an immutable variable

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

swift: To create a constant, type

A

let constantName = “value”

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

swift: To explicitly set the type of a variable, type

A

var myVariable: String = “value”

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

python: To turn a list of words into a dict with the keys being the unique words and the values being their frequency in the list, type

A

from collections import Counter
word_list = [‘apple’,’egg’,’apple’,’banana’,’egg’,’apple’]
counts = Counter(list1)

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

xcode: To show the console

A

click view / assistant editor / show assistant editor

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

swift: To print to the console, use the command,

A

print()

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

swift: To print something on the console on its own line, type

A

println()

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

swift: To evaluate a variable that is inside a string, type

A

println(“My name is (name_var)”)

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

swift: Interpolation is

A

evaluating a variable within a string

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

swift: To add a line break to a string type

A

\n

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

swift: To add a tab to a string type

A

\t

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

swift: To add an emoji to a string

A

click edit / emoji and symbols

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

swift: A double is

A

a float that can have 15 decimal places.

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

swift: If you do not specify the type “float” swift will assume a number with a decimal is a

A

double

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

swift: Booleans are written

A

lowercase

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

swift: To specify the type of a variable as a boolean, type

A

var my_var: Bool = false

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

swift: To convert a variable that is an integer into a Double, type

A

Double(myInt)

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

swift: When doing math, to control the order of operations, just use

A

parentheses

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

swift: When the operators in a math equation have the same priority, the equation is evaluated from

A

left to right

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

swift: To add 1 to an integer variable, type

A

myInt++

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

swift: To add 1 to an integer variable and assign it to another variable at the same time, you must put the

A

++ as a prefix. eg. ++myInt

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

swift: To subtract 1 from an integer variable in a short way, type

A

myInt–

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

swift: To evaluate to the opposite of the given boolean value, type

A

!false

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

swift: To specify that an array is a list of only strings, type

A

var myList: [String] = [“String1”, “String2”]

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

swift: To append items to the end of an array (using +=), type

A

myArray += [“New item1”, “New item2”]

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

swift: To return the attribute of an array that is the sum of the items, type

A

mylist.count

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

swift: To append a new item to an array, type

A

myArray.append(“new item”)

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

swift: To pop the last item of an array, type

A

myArray.removeLast()

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

swift: To remove an item from an array by its index, type

A

myArray.removeAtIndex(2)

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

swift: To insert a value into an array at index 2, type

A

myArray.insert(“value”, atIndex: 2)

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

swift: To create a single line comment in swift, type

A

//

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

swift: To create a dictionary, type

A

myDict = [“key”: “value”, “key”, “value”]

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

swift: To add a new dictionary item to myDict, type

A

myDict[“new key”] = “new value”

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

swift: myDict[“key name”] returns an

A

optional

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

swift: To pop/remove a dict item based on its key, type

A

myDict.removeValueForKey(“key name”)

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

swift: To make a for loop, type

A

for item in myArray {
println(item)
}

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

swift: to create a for loop for a range of 1 to 10, type

A

for item in 1…10 {
println(item)
}

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

swift: to create a rang of 1 to 10 using the greater than symbol, type

A

1..>9

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

swift: To make a loop that runs once before validating a condition, type

A

i = 0
do {
print(“string”)
} while i

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

swift: To create a while loop that increments, type

A

i = 0

while i

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

swift: To create a for loop that increments on one line, type

A

for var i = 0; i

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

swift: To create an if, else if, else, chained statement, type

A
if  i  3 {
    print("more")
} else {
    print("equal")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

to create a for loop that prints a string when the item is equal to 3 or 4, using a switch statement, type

A
for item in myArray {
    switch item {
    case 3, 4:
        print("string")
    default:
        print("")
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

swift: the “and”, “or” and “not”, operators are

A

&& || !

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

swift: To create a function, type

A

func functionName() {

}

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

swift: to define a function with parameters, type

A

func functionName(param1: Int, param2: String) {

}

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

swift: To create a function that has a return, you must

A

specify the return type, e.g.

func functionName() -> int {
    return 5
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

swift: To label function parameters so they are easily viewable in tab completion, type

A

func functionName(param1 1param1: Int, param2 param2: String) {

}

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

swift: When function params are labeled, you must

A

pass those labels in with the values when you call the function.

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

swift: When labeling your function parameters, you can succinctly make your param labels the same as the param names by typing

A

param1

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

swift: To declare the return of a function as a tuple with a boolean and a string, type

A

func functionName(param1: Int, param2: String) -> (Bool, String) {

}

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

swift: To create a tuple, use

A

parentheses and a comma

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

swift: To return the first index of a tuple, type

A

myTuple.0

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

swift: To unpack a tuple into variable names, type

A

var (name1, name2) = myTuple

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

swift: To set names to the indexes of a tuple that return from a function, so they can later be accesed as an attribute, type

A

func functionName() -> (name1: Bool, name2: String) {

}

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

swift: To unwrap the value of an optional, type

A

myOptional!

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

swift: If you have a function that only has a return if a condition is met, swift will make you

A

create another return for when the condition is not met.

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

swift: To be able to use a nil return type for when the required condition in a function is not met, you must

A
make the return type an optional by typing
func functionName() -> String? {
    return nil
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

swift: To safely unwrap an optional return with no chance of it crashing, type

A
if let myConstant = functionName("param") {
    myConstant
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

swift: an optional can either have

A

a value or a nil

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

swift: The safest way to unwrap an optional is to use

A

an if let statement

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

swift: To turn a string into an integer, type

A

myString.toInt()

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

swift: To change a function call from a string to an Int, type

A

myFunction(“param1”)?.toInt()

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

swift: an enum allows you to create

A

a new type and set the possible values for that type.

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

swift: To create an enum for the days of the week, type

A

enum Days {
case Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

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

swift: One benefit of an enum is that

A

xcode will yell at you if you spell it wrong.

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

swift: To choose a member from an enum, type

A

Enumname.Membername

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

swift: To access the raw value of an enum member, type

A

Enumname.Membername.rawValue

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

swift: To assign raw values to each of the members of an enum, type

A

enum Days: Int {
case Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7
}

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

swift: Adding a raw value to enum members allows you to

A

perform arithmetic on them, e.g.

Day.Monday.rawValue - Day.Monday.rawValue

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

swift: If you assign a raw value of 1 to the first member of an enum, swift will automatically

A

add incremental raw values to the rest of the members.

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

swift: To create a function with a switch statement in it, type

A
func functionName(param1: Int) -> String {
    switch param1 {
    case 1...5:
        return "string"
    case 6...10:
        return "string"
    default:
        return "string"
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

swift: When create a switch statement, you must end the case statements with a

A

colon

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

swift: To create an instance of an enum member by its raw value, type

A

var enumInstance = EnumName(rawValue: value)

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

swift: var myEnumInstance = EnumName(rawValue: value) returns

A

an optional, just in case you pass in a rawValue that does not exist.

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

swift: The two ways to unwrap an optional are

A

bang or if let

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

swift: Each raw value for every enum member must be

A

unique

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

swift: To give an enum member an associated value that is a string, type

A
enum TypeName {
    class MemberName(String)
}

let enumInstance = Typename.MemberName(“Set Associated Value”)

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

swift: To create an type member instance and pass in the associated value, type

A

var enumInstance = TypeName.MemberName(“Associated value string”)

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

swift: enum members must be

A

capitalized

86
Q

swift: to add a method to an enum type, just

A

include the method in the brackets of the enum.

87
Q

swift: For a method within an enum to make instances access themselves, the method must use

A

self.myAttribute

88
Q

swift: By default the init() { } method does not

A

take any parameters or return anything.

89
Q

swift: the init() { } method runs

A

upon instantiation

90
Q

swift: To use the init() { } method to set an attribute of every new instance automatically, type

A

init() {
self = TypeName.MemberName
}

91
Q

swift: A struct is a

A

class with attributes and methods

92
Q

swift: To create a struct with two attributes, type

A

struct Structname {
var attribute1: String
var attribute2: String
}

93
Q

swift: To overwrite a structs init() { } method (3 attributes) with a custom one that takes two parameters and also sets a default value to the third attribute, type

A

struct Structname {
var attribute1: String
var attribute2: String
var attribute3: String

    init(Param1: String, Param2: String) {
        self.attribute1 = Param1
        self.attribute2 = Param2
        self.attribute3 = "default"
    }
}
94
Q

swift: To create an init method in a struct that will require a user input and then set that input to an attribute of the current instance, type

A

struct StructName {
var attribute: String

init (param1: String){
    self.attribute = param1
} }
95
Q

swift: If a struct has no init method, it will

A

require values for all of its attributes to be passed in automatically.

96
Q

swift: If you decide to use an init method in a struct, make sure to include

A

all of the attributes that do not have a value.

97
Q

swift: classes do not automatically

A

create the init method for the attributes present like a struct does. This means that I must either give the attributes values or create an init method.

98
Q

swift: If the attributes of a class instance are var types, you can

A

change their value even if the instance you made is a constant.

99
Q

swift: To make my class inherit from a ParentClass, type

A

class ClassName: ParentClass {

}

100
Q

swift: To use this you must

class ClassName {
    var attribute = EnumName()
}
A

have enums init method set the enum to a default value.

101
Q

swift: To override a function inherited from a parent class, you must use the keyword

A

override func functionName() ->…

102
Q

swift: In order to override a method from the parent class the new method must have

A

the same name, parameters and return type

103
Q

swift: For a class that extends a parent class to call a method from the parent class that has been overwritten inside itself, you need to type

A

super.functionName(param1)

104
Q

swift: To create a function with a default value for a param, type

A

func functionName(_ param1:Double = 10.0) {

}

Note: Since you provide the value then the underscore denotes it is optional.

105
Q

swift: When overriding the init method from the parent class, any additional attributes must be

A

assigned first in the new init method above super.init()

106
Q

swift: To override a parent classes init method but still initialize everything necessary from the parents init method, type

(2 parent class params and 1 subclass param)

A

init(param1: Double, Param2: String, Param3: String) {
self.attribute = param1
super.init(param2:Param2, Param3:Param3)
}

107
Q

swift: a convenience initializer can only call

A

the designated initializer within its own class.

108
Q

swift: To specify that an init method is a convenience initializer, type

A

convenience init(

109
Q

swift: Initializers cannot call

A

a super classes convenience initializer

110
Q

swift: The init method of a subclass will need to take in params for

A

all of its own attributes as well as all of the attributes from the parent class.
The parent classes attributes will then be passed into the super.init

111
Q

swift: Computed attributes / properties can only be stored as a

A

var

112
Q

swift: To create a computed property, type

A

var attribute3: Double {
return attribute1 * attribute2
}

113
Q

swift: You cannot perform operations on

A

a Float with a Double

114
Q

swift: To be able to set a value to your computed attribute using instance.attribute = “new value”, type

A
var attribute3: Double {
    get {
        return attribute1 * attribute2
    }
    set {
        attribute = newValue
    }
}
115
Q

swift: in a computer attribute, the set { } methods newValue takes in the value from

A

instance.attribute = “new value”

116
Q

swift: A “read/write” computed attribute requires the

A

get { } and set { } methods

117
Q

swift: To create an attribute in a class that is an optional boolean, type

A

var attribute: Bool?

118
Q

swift: A struct is a value type, meaning that

A

when you assign a struct to a variable, it copies whatever was in the struct and now there are two independent structs. So changing the new struct variable doesn’t change the first.

119
Q

swift: A class is a reference type, meaning that

A

if you assign a class instance to a new variable, and then change an attribute of the new variable, the original instance is also changed.

120
Q

swift: enums are also

A

value types

121
Q

swift: attributes of a class must be set to

A

either let or var

122
Q

swift: A convenience initializer is basically a way to

A

send defaults to the designated initializer except the ones you want to manually send in upon instantiation, to save time.

123
Q

swift: To create a convenience initializer, type

A
convenience init(param1: Double) {
    self.init(param2: "default", Param 3: "default", param1: param1)
}
124
Q

xcode: The names of the 3 main panels from left to right are

A

navigator, editor, utility

125
Q

xcode: To make xcodes storyboard take on the shape of a phone rather than a square

A

click on “w any h any” and drag the overlay window into the desired shape.

126
Q

xcode: To see the icons you drag onto your storyboard

A

in the utility panel, click on “show the object library” circle icon, then click on the “icon view” button on the bottom left.

127
Q

xcode: After adding a new icon to the story board it is a good practice to

A

click the “editor” menu, and “size to fit content”

128
Q

xcode: To use the attributes inspector, click the

A

half diamond looking icon on the top on the utility panel.

129
Q

xcode: TO change the size of the phone simulator

A

go to the “window” menu, and the “scale”.

130
Q

xcode: To rotate the screen

A

in the simulator type command left

131
Q

xcode: To center a button on the storyboard

A

Open the “document outline”, the blue button on the bottom left. select the button. Click the blue button on the bottom right called “align” and add the vertical and horizontal constraints.

132
Q

xcode: in images.xcassets, an image set it

A

a set of the same image in a few sizes

133
Q

xcode: If switching a button from text to image, you must

A

remove the title from the utility panel.

134
Q

xcode: The iphone 3, 4/5, 6 use the pixel densities

A

1x, 2x, and 3x respectively.

135
Q

xcode: To connect a UI element to code

A

hold control, then click and drag the element to the assistant editor

136
Q

xcode: To make a UI element that you made hidden in the attribute inspector no longer hidden, type

A

elementName.hidden = false

137
Q

xcode: The shortcut to view files navigator is

A

command 1

138
Q

xcode: IBoutlets are usually

A

weak

139
Q

xcode: The most common type of button action is

A

touch up inside

140
Q

xcode: To change the text of a UILabel instance, type

A

instanceName.text = “new label”

141
Q

swift: If you create an array within a function, its scope is

A

limited to only inside the function.

142
Q

swift: Commands that need to happen immediately should be added to the

A

viewDidLoad() method

143
Q

swift: To generate a randon number, type

A

let diceRoll = Int(arc4random_uniform(7))

144
Q

xcode: An orange line in the story board means that

A

the positioning of the UI element is ambiguous

145
Q

xcode: To fix ambiguous positioning of UI elements, press

A

the triangle button on the bottom right of the story board called “resolve auto layout issues”, then press “reset to suggested constraints”

146
Q

xcode: To make the size of a label auto adjust to a string

A

set the lines attribute to 0

147
Q

xcode: The app icons you upload should be

A

squares because xcode automatically rounds the corners

148
Q

swift: an @IBOutlet functions as

A

an import of an object which you can use to alter it’s attributes.

149
Q

swift: the launch screen is

A

the screen that temporarily displays after the app is launched

150
Q

swift: The states for a button are

A

highlighted
selected
normal
disabled

151
Q

swift: When setting constraints using the pop up on the bottom right, make sure to set

A

Update Frames: to “Items of new constraints”

Note: This places your element where your constrint will put then on the device.

152
Q

swift: Outlets should be placed … while Actions should be placed

A

Outlets: Top of the view

Actions: Bottom of the view

153
Q

swift: To set a views background color attribute to orange, type

A

view.backgroundColor = UIColor.orangeColor()

154
Q

swift: When creating a new view, instead of starting a new blank swift file, use

A

Cocoa Touch Class under iOS source

155
Q

swift: New view controller files should be a subclass of

A

UIViewController

156
Q

swift: When you delete an action from the view controller you must also delete

A

the reference to that action by right clicking on the object in the storyboard.

157
Q

swift: To make a button that upon being clicked takes you to another view

A

hold control, then drag the button onto the next view in the storyboard.

158
Q

swift: To change the title of a button, type

A

buttonInstance.setTitle(“New Title”, forState: .Normal)

159
Q

swift: To add a navigation bar

A

select a view, then in the menu, editor / imbed in / navigation controller

160
Q

swift: a shortcut to make a label resize to fit all of the text in it is

A

command =

161
Q

swift: One UI element can have both

A

an Outlet and an Action

162
Q

swift: Initial setup for a view should be called in the function called

A

viewDidLoad

163
Q

swift: If you are triggering animations, it is preferable to start them in the function called

A

viewDidAppear rather than viewDidLoad

164
Q

swift: The difference between viewDidLoad vs. viewDidAppear is

A

viewDidLoad only runs once and after the view is constructed. After loading to memory it doesn’t run again.
viewDidAppear runs anew every time the view appears.

165
Q

swift: An example of a hierarchical navigation is

A

the iphone settings.

166
Q

swift: For a quick one off action a user must take, the preferred segue is

A

modal

167
Q

swift: To create a new view, just

A

drag a view controller element out of the object library

168
Q

swift: To send information from one view to another you must use the current views

A

prepareforSegue:Sender: method

169
Q

swift: To be able to choose a segue for your prepareforSegue:Sender: method, you must first

A

give the segue an identifier in the attributes inspector

170
Q

swift: To access the outlets on the destination view controller from within the current one, use

A

segue.destinationViewController as ViewControllerName

171
Q

swift: To send from the current view to the next using a segue, in the curent view you must type

A
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "segueIdentifier" {
            let instanceOfNextViewController = segue.destinationViewController as! TitleOfViewController
            TitleOfViewController.variableInNextController = "value"
        }
    }
172
Q

swift: when trying to send info from the current view to the next, your app will crash if you try to

A

create an instance of the next view in the current one and then change a UI element before the view has loaded.

173
Q

swift: To send information from the current view to the next, you must

A

create a var on the next view and in the current view create an instance of the next view controller and set the value of the var. Then only apply that var to a UI element in the viewDidLoad() method for after the view loads.

174
Q

swift: for images views, you must specify the

A

hight and width constraints in the pin menu, next to the align menu

175
Q

swift: When you upload vector images, to set xcode to recognize them as vector

A

select the image and in the attributes inspector, set scale factors to Single Vector.

176
Q

swift: To turn anyObject into a string, type

A

as String, after it

177
Q

swift: To assign a ViewController to a view

A

Go to the identity inspector and set the class to the name of the new ViewController file.

178
Q

swift: The library to use when playing audio is called

A

AVAudioPlayer

179
Q

swift: If you want a variable that is being assigned inside a function to have global scope, you must

A

initialize the variable outside the function, and then update it within the function.

180
Q

swift: always make sure that after you create a variable with var, that you do not

A

use var on the same variable again.

181
Q

swift: To create a button that plays an audio file, type

A

import AVFoundation

var audioPlayer: AVAudioPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()
        if var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3") {
            var filePathURL = NSBundle.mainBundle().URLForResource("movie_quote", withExtension: "mp3")
            audioPlayer = AVAudioPlayer(contentsOfURL: filePathURL, error: nil)
        } 
    }

@IBAction func playAudio() {
audioplayer.stop()
audioPlayer.play()
}

182
Q

swift: To change the speed of the AVAudioPlayer playback, type

A
audioPlayerInstance.enableRate = true
audioPlayerInstance.rate = 0.50
183
Q

swift: To check the exact size of a constraint, just

A

click on it and check the attributes inspector

184
Q

swift: To declare the time of an AVAudioPlayer instance to a certain time in the audio file, type

A

audioPlayerInstance.currentTime = 0.0

185
Q

swift: When renaming a ViewController.swift file, the 4 things you must do are

A

Change the file name
Change the name of the class inside the file
Change the comment at the top of the file
Go to the story board and click on the view, then in the identity inspector, select the new class name.

186
Q

swift: To format a date, type

A
let currentDateTime = NSDate()
let formatter = NSDateFormatter()
formatter.dateFormat = "ddMMyyyy-HHmmss"
let recordingName = formatter.stringFromDate(currentDateTime)+".wav"
187
Q

swift: When assigning a function into a var, do not

A

add the parentheses

188
Q

swift: To filter an array, type

A

var filteredArray = fullArray.filter(functionThatReturnsTrueOrFalsePerItem)

189
Q

swift: The nested function in a closure has

A

access to variables assigned inside the function it was nested in.

190
Q

swift: closures maintain

A

the value of variables inside the nested functions.

191
Q

swift: When assigning a closure into a var,

A

add the parentheses

192
Q

swift: Core data allows you to

A

save settings that you’ve changed in your app

193
Q

swift: To choose a file to show in the assistant editor,

A

hold alt and click on it

194
Q

swift: To change the launch screens view, change the

A

LaunchScreen.xib file in the navigator

195
Q

xcode: To clean xcode’s cache, press

A

command shift k

196
Q

xcode: to force a build of your code, press

A

command b

197
Q

xcode: To go to the home screen on the mac ios simulator,

A

in the simulator, go to the “hardware” menu and click “home”

198
Q

swift: To be able to assign raw values to enum members you must

A

define the raw values type. e.g.
enum EnumName: Int {
}

199
Q

swift: To enter the swift repl, type

A

swift

200
Q

swift: To exit the swift repl, type

A

control d

201
Q

swift: To change the background image, type

A

under viewDidLoad()

self.view.backgroundColor = UIColor(patternImage: UIImage(named: “background.png”))

202
Q

swift: The properties of the UIView class that are animatable are

A

frame, bounds, center, transform, alpha, backgroundColor, contentStretch

203
Q

swift: To make the background color of my view red, type

A

myView.backgroundColor = UIColor.redColor()

204
Q

swift: To create two views that switch with an animation, type

A

self. container.frame = CGRect(x: 60, y: 60, width: 200, height: 200)
self. view.addSubview(container)
self. redSquare.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
self. blueSquare.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
self. redSquare.backgroundColor = UIColor.redColor()
self. blueSquare.backgroundColor = UIColor.blueColor()
self. container.addSubview(self.redSquare)

UIView.transitionWithView(self.container, duration: 1.0, options: UIViewAnimationOptions.TransitionCurlUp, animations: {
            views.frontView.removeFromSuperview()
            self.container.addSubview(views.backView) }, completion: { finished in
                // code to be applied once the animation has completed  
        })
205
Q

swift: To create a simple rotation animation, type

A

UIView.animateWithDuration(0.5, animations: { self.myView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
})

206
Q

python: if functions are a first class citizen that means you can

A

pass a function into a function

assign a function to a variable

207
Q

python: In functional programming, your functions should not have

A

side effects

208
Q

python: To create a lambda function, type

A

(lambda x: x*5)(2)

209
Q

python: **my_dict converts {“key”: “values”} to

A

“key” = “value”

210
Q

python: a closure is

A

a function that returns a pointer to a function nested inside of it, which is then assignable into a variable.

e.g.

closure_var = closure() (which returns a pointer to a nested function)
closure_var(param1)

211
Q

python: A closure must return

A

a pointer to an inner nested function (it is the name of the function with no parentheses)