Swift Flashcards
python: To read a txt file into python, type
file = open(“/words.txt”, “r”)
words = file.read()
file.close()
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
from collections import Counter
counts = Counter(my_word_list)
swift: UIkit stands for
User Interface Kit
swift: var variableName only needs to be used
upon instantiation.
swift variable names should be written in
camelcase
swift: A constant is
an immutable variable
swift: To create a constant, type
let constantName = “value”
swift: To explicitly set the type of a variable, type
var myVariable: String = “value”
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
from collections import Counter
word_list = [‘apple’,’egg’,’apple’,’banana’,’egg’,’apple’]
counts = Counter(list1)
xcode: To show the console
click view / assistant editor / show assistant editor
swift: To print to the console, use the command,
print()
swift: To print something on the console on its own line, type
println()
swift: To evaluate a variable that is inside a string, type
println(“My name is (name_var)”)
swift: Interpolation is
evaluating a variable within a string
swift: To add a line break to a string type
\n
swift: To add a tab to a string type
\t
swift: To add an emoji to a string
click edit / emoji and symbols
swift: A double is
a float that can have 15 decimal places.
swift: If you do not specify the type “float” swift will assume a number with a decimal is a
double
swift: Booleans are written
lowercase
swift: To specify the type of a variable as a boolean, type
var my_var: Bool = false
swift: To convert a variable that is an integer into a Double, type
Double(myInt)
swift: When doing math, to control the order of operations, just use
parentheses
swift: When the operators in a math equation have the same priority, the equation is evaluated from
left to right