Session 2: Learn to Code with SWIFT Flashcards
What is a variable?
Used to store information like some labels to be referred later and stored in memory. Variables are containers of information and link between users and software.
Give an example of variable and how it stores in computer?
For example my age is 23. But computer only works with 0 and 1 so, 23 is for us. Now age is a variable and it’s value which is 23 stores inside the RAM(Random Access Memory). In programming perspective: var age = 23.
What is an assignment operator?
Or = assigns the variation to an operator which can be string “like this” or value e.g. 30.
What can be after assignment operator?
Assigns the value to variable.
3 main kinds of operators?
Unary(single), Binary(Double) and Ternary(Three)
Write the samples in codes for operators?
Unary(Only amICoolPerson)—> var amIACoolPerson = true, amICoolPerson = !amICoolPerson. Binary(name and this is great)—> var name = “this is great”. ….
What is string and it’s length?
A finite sequence of characters(either word or symbols or letter). The length can be from zero to a number.
What is string manipulation? Using a string from another variable and using inside another variable like: var name = “ali” , var family = “sadeghi” var fullName = name “ “ family.
Using a string from another variable and using inside another variable like: var name = “ali” , var family = “sadeghi” var fullName = name “ “ family.
What is string interpolation?
Using all previously used strings inside new string by using ((variable)) like var fullName2 = “(first) (last) is (age) years old”
What is append function?
When we want to add an object at the end of a variable like: var fullName.append = “AAA” —> Becomes: ali sadeghiAAA
Write sample code contains strings to change bad words?
var sentence = “what the F* you are As*”, if sentence.contains(“f*) || sentence.contains(“As*) { sentence.replaceingOccurrences (of: “f*” , with “Googooli”
What are the main types of Numbers?
3 groups: Integer, Float and Double
What is Integer?
Numbers with no fraction. It can be either positive, negative or zero.
What is difference between signed and assigned integers?
When we put a number we assign the integer to a limited number of integers can carry. e.g. UInt8 only can carry 8 digits. But if we don’t mention anything SWIFT automatically fixes upon needs.
What is Double Data type?
For when we use long digits or fractional we use Double. Double type is the preferred type suggested by SWIFT by default.