NEW
Font size
WorksheetsPathway
Total questions: 45
Worksheet time: 1hrs 8mins
Which keyword is used to declare a constant in Swift?
let
var
const
In Swift, can the value of a constant be changed after it has been declared?
True
False
Which Swift data type is used to represent a sequence of characters?
String
Character
Array
Set
Which property can be used to get the number of characters in a string in Swift?
count
length
size
sizeOf
How can we write a single-line comment in Swift?
<!-- This is a comment -->
/* This is a comment */
// This is a comment
# This is a comment
What is readLine() used for in Swift?
To read a text file
To read user input from the command line
To read data from a URL
To read an array
In Swift, what does the ! symbol mean when placed after a variable?
It declares a new Optional variable
It increments the value of a variable
It implicitly unwraps an Optional variable
It indicates a factorial operation
How do you create an array of integers in Swift?
var array = [Integer]()
var array: [int] = []
var array: [Int] = []
var array = []
What is the difference between information and data?
Data is raw facts, while information is processed and meaningful data
Information is processed data, while data is raw facts
Information is more valuable than data
There is no difference
How do you declare a constant in Swift?
let name = "John"
const name = "John"
var name = "John"
constant name = "John"
What is the difference between a variable and a constant?
Constants can change their value, variables cannot change their value
Variables can change their value, constants cannot change their value
Variables and constants can both change their values
Variables and constants cannot change their values
How is the ternary operator used in Swift?
if condition: value1 else: value2
condition then value1 else value2
if condition then value1 else value2
condition ? value1 : value2
How do you declare a function in Swift?
function name() {}
func name() {}
define name() {}
declare name() {}
What is an Action
A variable that stores the state of a UI element.
A connection between two UI elements.
A function in Swift code that is triggered by a user interaction with a UI element.
A property of a UI element.
What is the difference between a function parameter and an argument label?
Function parameters are used to pass data to a function, argument labels are used to name the parameters when calling the function
Function parameters are used to name the parameters when calling the function, argument labels are used to pass data to a function
Function parameters and argument labels are the same thing
There is no difference
Write Swift code to append the value 6 to the end of the numbers array.
numbers.append(6)
numbers += 6
numbers.add(6)
numbers.pop(6)
What is a View Controller Scene Hierarchy?
What is a View Controller Scene Hierarchy?
The arrangement of Views within a View Controller.
. A hierarchical representation of the View Controllers and their relationships within an application.
The way in which data is passed between View Controllers.
What is an Outlet?
A function that responds to user interactions.
A connection between a UI element in Interface Builder and a variable in Swift code.
A property of a UI element.
A method that modifies the state of a UI element.
Which file is responsible for handling the app's initial launch and setup?
ViewController
SceneDelegate
AppDelegate
Main
Which file contains the app's icons, images, and other?
AppDelegate
Info.plist
ViewController
Assets.xcassets
Which keyboard shortcut should I use to open the correct view controller?
(control+option+command) + return
(control+option+command) + return right
(control+option+command) + up
(control+option+command) + down
Which method is called when a UIViewController is fully removed from the screen?
viewDidLoad
viewWillAppear
viewDidAppear
viewDidDisappear
What is the relationship between the ViewController and the Main.storyboard file?
They are completely separate entities.
The ViewController file contains the UI design for the Main.storyboard file.
The Main.storyboard file defines the UI layout, and the ViewController class handles the logic behind that UI.
The Main.storyboard file is a blueprint for the ViewController class.
How can you set a custom font for a UILabel programmatically?
myLabel.font = "Arial"
myLabel.setFont(name: "Arial", size: 16)
myLabel.font = UIFont(name: "Arial", size: 16)
myLabel.font = UIFont.systemFont(ofSize: 16)
How can you access the UINavigationController from within a UIViewController?
self.navigationController
view.navigationController
superview.navigationController
navigationController
How can you programmatically change the background color of a UINavigationBar?
navigationBar.backgroundColor = .red
navigationBar.setBackgroundColor(.red)
navigationBar.barTintColor = .red
navigationBar.setBarTintColor(.red)
Which method is used to create a UIAlertController in Swift?
UIAlertController.create(title: "Alert", message: "Message")
showAlert(title: "Alert", message: "Message")
UIAlertController(title: "Alert", message: "Message", preferredStyle: .alert)
UIViewController.showAlert(title: "Alert", message: "Message")
How can you display an image from the Assets.xcassets file in a UIImageView?
myImageView.image = UIImage(named: "myImage")
myImageView.setImage(named: "myImage")
myImageView.image = "myImage"
Which area in the Xcode interface allows you to view and edit your project files?
Toolbar area
Debug area
Editor area
Inspector area
Which area in Xcode allows you to view and modify the properties of a selected object, such as a UI element or a file?
Toolbar area
Debug area
Editor area
Inspector area
What is the ouput of the following code?
let myArray = [1, 2, 3].enumerated().reversed()
print(myArray)
[(2, 3), (1, 2), (0, 1)]
[(0, 1), (1, 2), (2, 3)]
[(2, 3), (0, 1), (1, 2)]
What is the ouput of the following code?
func sumOfSquares(array: [Int]) -> Int {
var sum = 0
for i in 0..<array.count {
sum += array[i] * array[i]}
return sum}
print(sumOfSquares(array: [1, 2, 3]))
6
14
Error
[1,2,3]
What is the ouput of the following code?
let myOptional: String? = nil
let myString = myOptional?.uppercased()
print(myString)
Hello
Error
Nil
What is the ouput of the following code?
func findMissingNumber(array: [Int]) -> Int {
let n = array.count + 1
let expectedSum = n * (n + 1) / 2
let actualSum = array.reduce(0, +)
return expectedSum - actualSum }
print(findMissingNumber(array: [1, 2, 4, 5]))
15
Error
3
[1,2,4,5]
What is the output of the following code?
func fibonacci(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 1
} else {
return fibonacci(n: n - 1) + fibonacci(n: n - 2) } }
print(fibonacci(n: 10))
10
Error
55
'10'
What is the output of the following code?
func isPalindrome(str: String) -> Bool {
let reversedString = String(str.reversed())
return str == reversedString }
print(isPalindrome(str: "racecar"))
true
false
error
"racecar"
What is the output of the following code?
let myArray = [1, 2, 3]
let myTuple = (myArray[0], myArray[1])
print(myTuple.1)
1
2
error
1 2
What is the output of the following code?
func findMissingNumber(array: [Int]) -> Int {
let n = array.count + 1
let expectedSum = n * (n + 1) / 2
let actualSum = array.reduce(0, +)
return expectedSum - actualSum }
print(findMissingNumber(array: [1, 2, 4, 5]))
1 2 3
3
15
Error
What will the following code print?
func makeIncrementer(incrementAmount: Int) -> () -> Int {
var total = 0
let incrementer: () -> Int = {
total += incrementAmount
return total }
return incrementer }
let incrementByTwo = makeIncrementer(incrementAmount: 2)
print(incrementByTwo())
print(incrementByTwo())
2 4
2 0
4 6
2 2
What will the following code print?
func outer() {
func inner() {
print("Inner")}.
inner() }.
outer()
inner
outner
What is the output of the following code?
let numbers = [1, 2, 3, 4, 5]
let firstThree = numbers.prefix(3)
print(firstThree)
[1, 2]
4, 5]
[1, 2, 3]
What is the output of the following code?
let numbers = [1, 2, 3, 4, 5]
var sum = 0
for number in numbers {
sum += number }
print(sum)
10
15
20
5
What is the output of the following code?
let text = "Swift is fun"
let index = text.firstIndex(of: "f")
print(index)
4
5
6
7
What is the output of the following code?
let myArray = [5, 1, 4, 2, 3]
let sortedArray = myArray.sorted()
print(sortedArray)
[5, 1, 4, 2, 3]
[3, 2, 4, 1, 5]
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
Choose the command to print the string "Hello, John!" using string interpolation given let name = "John"
print("Hello, \(name)!)
print("Hello, " + name + "!")
print("Hello, " + name)!
print("Hello, " + name)
