Computer SCI

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the difference between += and append() when adding elements to an array in Swift?

+= adds an array of elements to an array, while append() adds a single element.

What is the output of the following code snippet? let nums = [1, 2, 3, 4, 5] let result = nums.reduce(0, { x, y in x + y }) print(result)

15

What is the output of the following code? let nums = [1, 2, 3, 4, 5] let result = nums.reduce(0) { $0 + $1 } print(result)

15

Which operator is used for optional chaining in Swift?

?

What is a protocol in Swift?

A blueprint for a class, struct, or enumeration

What is an @escaping closure in Swift?

A closure that can be passed as an argument to another function and executed asynchronously.

What is a computed property in Swift?

A property that is computed based on the value of one or more other properties.

What is a lazy property in Swift?

A property that is initialized only when it is first accessed.

What is Not a function of Swift programming

Dynamic Typing

What is the output of the following code? let name = "John" let greeting = "Hello, \(name)!" print(greeting)

Hello, John!

What does the defer keyword do in Swift?

It executes a block of code after a function returns.

Which of the following statements is true about Swift's guard statement?

It is used for exiting a scope early in Swift.

What is Not a data type of Swift

Long

Which of the following statements is true about optionals in Swift?

Optionals can be used with any data type.

Which of the following is not a property of a class in Swift?

Procedures

What is the difference between a struct and a class in Swift?

Structs are value types while classes are reference types

What is the output of the following code? let num = 5 if case 1...10 = num { print("The number is between 1 and 10") } else { print("The number is not between 1 and 10") }

The number is between 1 and 10

Which of the following is not a feature of optionals in Swift?

They are automatically unwrapped

Which of the following is not a feature of a structure in Swift?

They can be inherited from other structures

What is the purpose of guard statement in Swift?

To check for a condition and exit early if it's not met

Var is used to define a variable. T or F

True

Which of the following is not a collection type in Swift?

Tuple

Which among the following is the feature of tuple in Swift?

Tuples can be decomposed into individual variables The values within a tuple can be of any type A tuple type is a comma-separated list of types, enclosed in parentheses.

Which of the following is not a way to unwrap an optional in Swift?

Using the "?" operator

Which keyword is used to define a class in Swift?

class

Which method is used to extract values of a given type from an Array in Swift?

flatMap

Which keyword is used to define a closure in Swift?

func

Which keyword is used to define a function in Swift?

func

Which of the following is NOT a correct way to declare a function in Swift?

func increment(_ num: Int) -> { num + 1 }

Which keyword makes the enum store its payload with a layer of indirection in Swift?

indirect

Which among the following is false with respect to map in Swift?

iterates through array

Which keyword is used to declare a constant in Swift?

let

How to define an array with repeated values?

let arrayOfStrings = Array(repeating: "Swift",count: 4)

Which of the following is NOT a correct way to declare an array in Swift?

let names = Array<String>(["Alice", "Bob", "Charlie"])

Which keyword enables a method of a struct to change the value of the struct itself in swift?

mutating

How to conver the given String to uppercase in Swift? Given let string = "HhEeLlLlOo"

string.uppercased()

Which type are arrays in Swift?

value

Which of the following is not a valid way to define an optional in Swift?

var bool: Optional<Bool>

What is the difference between while and repeat-while loops in Swift?

while checks the condition at the beginning of the loop, while repeat-while checks it at the end of the loop.

Which of the following is not a control flow statement in Swift?

while-do


Ensembles d'études connexes

Module 23: Studying and Encoding Memories

View Set

Chapter 16 - Small Business Entrepreneur's

View Set

Chapter 8 The Appendicular Skeleton

View Set

Chapter 51, Assessment and Management of Patients With Diabetes

View Set

Combo with "10.25.2014, Stats ch 6 Probability and unit normal table)" and 21 others

View Set

BEM 241: Inventory management - How much to order

View Set

(with random Paige Mnemonic) SPINE--PTP IV

View Set