FlashKeepers

Swift · College · College and University

Swift I: Basics and Optionals

Swift constants and variables, types, collections, control flow, functions, optionals, optional chaining and guard.

About this set

42 basic cards for College Swift. Set 1 of 4 in Swift. It opens with "In Swift, how do you declare a constant that cannot be changed?" and "What keyword declares a variable in Swift?". Study it alongside the other College sets below.

42 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

In Swift, how do you declare a constant that cannot be changed?
Show answerUse the let keyword, e.g. let name = "John"
What keyword declares a variable in Swift?
Show answervar
What is type inference in Swift?
Show answerThe compiler automatically determines a variable's type based on the assigned value
How do you explicitly specify a type in Swift?
Show answerUse a colon followed by the type name, e.g. let count: Int = 5
Should you use let or var for a value that never changes?
Show answerUse let
What is the Int type in Swift?
Show answerA whole number with no decimal point, e.g. 42 or -17
What is the Double type in Swift?
Show answerA floating-point number, e.g. 3.14 or -0.5
What is the String type in Swift?
Show answerA sequence of characters, declared with double quotes, e.g. "Hello"
What is the Bool type in Swift?
Show answerA boolean value that is either true or false
What operator checks the type of a value in Swift?
Show answeris
How do you cast a value to a different type in Swift?
Show answerUse as or as? or as!, e.g. value as Int
How do you declare an array in Swift?
Show answerUse square brackets, e.g. let numbers = [1, 2, 3] or var items: [String] = []
How do you access an element in a Swift array?
Show answerUse the index in square brackets, e.g. numbers[0] gets the first element
What does the append method do on a Swift array?
Show answerAdds a new element to the end of the array
How do you find the number of elements in an array?
Show answerUse the count property, e.g. numbers.count

27 more cards in the app

Study this set free