App Development with Swift Final

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

What is the result of the following block of code? let sum = 99 func computeSum(scores [Int]) -> Int { var sum = 0 for score in scores{ sum += score } return sum } computeSum(scores: [70, 30, 9])

109

What is the value of myNumber at the end of the following code? let x = 2 let y = 4 let z = 6 let myNumber = x + y + z

12

What is the value of myNumber at the end of the following code? let x = 2 let y = 4 let z = 6 let myNumber = x * y - z

2

What is the value of myNumber at the end of the following code? let x = 2 let y = 4 let z = 6 let myNumber = x + y * z

26

What is the value of myNumber at the end of the following code? let x = 2 let y = 4 let z = 6 let myNumber = (x + y) * z

36

What will be returned at the end of the function? func calculateResult(a: Int?, b: Int?, c: Int?) -> Int { guard let aValue = a else {return 0} guard let bValue = b else {return aValue} guard let cValue = c else {return bValue} return aValue + bValue + cValue } calculateResult(a: 4, b: 8, c: nil)

8

Which logical operator means "less than or equal to"?

<=

Which logical operator means "equals"?

==

Which logical operator means "greater than"?

>

Which code snippet will compile correctly? A var items: [Any] = [5, "Bill", 6.7, Dog()] B var items: [String] = [5, "Bill", 6.7, Dog()] C var items: [Double] = [5, "Bill", 6.7, Dog()] D var items: [String] = [5, "Bill", 6.7, Dog()]

A

Which of the following is not a commonly used protocol included in the Swift standard library

Sound player

Given the following code, what is the resulting type of ox? let o: Character = "O" let x: Character = "x" let ox = String(o) + String(x)

String

Identify the issue with the code snippet below: let x = 14 let y = 2.5 let result = x * y

The code with not compile. x is a Int and y is an Double.

Which of the following statement is true about the function below? func greet(name: String) { print("Hello, \(name)") }

The function has no return value.

Why does the following function not compile? func increment(_ value: Int by amount: Int) -> Int { return value + amount }

The function parameters aren't separated by commas

Which of the following would be best represented with a variable?

age

When you conditionally downcast from one type to another and store the value in a constant, which combination of keywords is NOT used?

as!

What property would you modify if you wanted to add a badge to a tab?

badgeValue

To add padding around the edges of your scroll view content, which property would you change?

contentInset

A .default row action style will result in a gray action button.

false

T/F The printBottleCount() and print(bottleCount) will print the same information. func printBottleCount() { let bottleCount = 99 print(bottleCount) } printBottleCount() print(bottleCount)

false

T/F: The print(age) and printMyAge() will print the same information. var age = 55 func printMyAge() { print("My age: \(age)") } print(age) printMyAge()

false

A function can be called by using the code below. How was the function declared? let value = multiply(5, by: 4)

func multiply(_ first:Int by:Int) -> Int

Which of the following code snippets uses the valid optional binding syntax?

if let dogName = owner.dogs.first {}

Using type inference, which of the following variables would be assigned in a double type?

let speedLimit = 75.0

What value would you assign to the previous answer to hide a badge?

nil

If statusCode is a tuple with five values, what is the proper way to access the fifth value?

statusCode.4

Which of the following would be best represented with an enumeration? T-shirt sizes favorite numbers vehicle speeds

t-shirt sizes

Why might you NOT use a scroll view?

to display content that's smaller than the desired display area

T/F: Any initializer that might return nil is called a failable initializer.

true

T/F: Each constant and variable lives within some sort of scope, a place where it's visible and accessible. There are two different levels of scope: global and local.

true

T/F: Swift provides two special types: Any and AnyObject. Any, as the name implies, can represent an instance of any type: strings, doubles, functions, or whatever. AnyObject can represent any class within Swift, but not a structure.

true

T/F: The following two enum code snippets are functionally equivilant. enum CompassPoint { case north case east case south case west } enum CompassPoint { case north, east, south, west }

true

Which of the following is a possible value for the code snippet below? var correctAnswer: Bool =

true

You can use a table view without a table view controller

true

Which keyword is used to declare a variable

var

Which of the following declares a double with a value of 4.2 that can be set to nil at a later date?

var height: Double? = 4.2

In what method should you place code to do additional initialization of views?

viewDidLoad()

Which of the following would be LEAST IDEAL to be represented with an enumeration? wifi network names professional basketball teams shoe brands

wifi network names

Which logical operator means "OR"?

||

What is the overall purpose of the following code? if height != nil { }

Checks if height contains a value, but does nothing after the check

Which protocol must be adopted to sort objects using the < or > operator?

Comparable

What is the result of the following block of code? let sum = 99 func computeSum(scores: [Int]) -> Int { var sum = 0 for score in scores{ sum += score } return sum } let sum = computeSum(scores: [70, 30, 9])

Compiler error; sum cannot be defined twice in the same scope.

What is the operator called when it has an arithmetic symbol in front of the equals sign = ? myScore += 100

Compound assignment operator

Which navigation style do most game apps use?

Content driven

Is a model controller a model, view, or controller object?

Controller

Which of the following is NOT true about controller objects?

Controllers should not know about views or model objects.

Which protocol must be adopted to provide custom text when using the print function?

CustomStringConvertible

When should you use a tab bar controller?

When you app has distinct modes

Which data source method is NOT required for table views?

numberOfSections (in: )

Which logical operator means "NOT"?

!

What is the value of mood after executing the following code? let cookies = [Cookie(.chocolate), Cookie(.peanutButter), Cookie(.blackAndWhite)] let mood = cookies.count() > 2 ? ":)" : ":|"

":)"

Given the following code, what is the resulting value of mathExpression? let b = 5 let m = "3" let x = 5 let mathExpression = "Solve for x. 20 = \(m)x + \(b)"

"Solve for x. 20 = 3x + 5"

What will the following code print to the console? Print("Testing, Testing, 1-2-3")

"Testing, Testing, 1-2-3"

What will print to the console when executing the following code? var weight = 52 if weight <= 50 { print("Have a great flight.") } else { print("There is a $25 fee for your luggage.") }

"There is a $25 fee for your luggage."

What will the following code print to the console? var score = 0 score += 100 score /= 100 print(score)

1

Which of the following is are the three primary goals of swift?

Safe, fast, expressive

Which segue adapts its presentation style from modal to push if a navigation controller is present?

Show

What will print to the console when executing the following code? var time = 6 if time < 12 { print("Good morning") } else if time < 20 { print("Good afternoon") } else { print("Good evening") }

"Good morning"

Which logical operator means "AND"?

&&

Why does the folowing expression return false? "Jonathan" == "jonathan"

An uppercase character and lowercase character aren't the same thing.

What will be the value of grade after execuring the following code? var grade: Character let score = 78 switch score { case 90...100: grade = "A" case 80...89: grade = "B" case 70...79: grade = "C" case 61...69: grade = "D" default: grade = "F" }

C

If a variable can be set to any given structure, what's the variable's type?

Any

Which function returns two integers? A func getRequestError() -> (String, Int) B func getRequestError() -> (Int, Int) C func getRequestError() -> (Int, Int, Int) D func getRequestError()

B

Which protocol must be adopted to check equality between two instances of a type?

Equatable

How can you adopt a custom protocol for a type defined in the Swift standard library?

Extend the type using an extension

What navigation style does the music app use?

Flat

Which navigation style does the mail app use?

Hierarchial

Which navigation style does the settings app use

Hierarchial

You can perform a segue programmatically as long as the segue has been given a/an:

Identifier

Which of the following values would be best represented with a constant?

Player name

Which of the following is a great environment for prototyping Swift code?

Playgrounds (not xcode, safari, or terminal)

Why is self in front of the property names of this initializer? Check all that apply. struct ThemePark { var name: String var numEmployees: Int var mostPopularRide: String init (name: String, numEmployees: Int, mostPopularRide: String) { self.name = name self.numEmployees = numEmployees self.mostPopularRide = mostPopularRide } }

It helps the Swift compiler distinguish between the parameters and properties with the same name.

Which keyword is used to declare a constant?

Let

Which of the following is NOT a reason for declaring most values as constants?

Most values never change

A navigation bar includes a _____ property that contains a title and a set of buttons.

Navigation Item

Will the following code snippet compile? Why? let name = "Joe" name = "Sally" print(name)

No, because name is a constant and cannot be modified

Which of the following would be best represented with an enumeration? A Names of people in the room B Political parties C Addresses D Compass degrees

Political parties

What is NOT the purpose of the guard statement?

To perform work that cannot be done with an if statement.

T/F it is possible to call ViewWIllDisappear without a corresponding call to viewDidDissappear

True

T/F: An optional represents two possibilities: Either there is a value and you can use it, or there isn't a value at all.

True

T/F: Any variable declared in global scope is called a global variable, and a variable declared in local scope is a local variable.

True

T/F: Enumerations define a common type for a group of related values.

True

Which of these are features of swift that make it a "safe language"

Type safety, type inference, error handling, optionals.

What classes are NOT inherited from UIScrollView?

UIView

Which of the following is true about view objects?

View objects display information and a view controller controls a view

Of the life cycle methods in this lesson, which one will execute first? A viewWillAppear(_: ) B viewDidAppear(_: ) C viewDidLoad(_: ) D viewDidDisappear(_: )

ViewDidLoad(_:)

In what method should you place code to refresh your views?

ViewWillAppear(_:)

In what method should you place code to execute long running code?

ViewdidAppear

When is it appropriate to use the as! operator?

When you need to downcast from one type to another and you can guarantee the type is valid

When you declare a string, how do you set the initial value?

With a string literal

To compare two strings, how would you check for equality?

With the operator ==

Will the following code snippet compile? Why? let number: Double = 3

Yes, because the compiler will assign the value 3.0 to number

Is the following initializer a valid failable initializer? struct ReportCard { var student: String var averageGPA: Double init? (studentName: String, gpa: Double) { self.student = studentName self.averageGPA = gpa } }

Yes; it's valid, but probably shouldn't be marked as failable since it never returns nil.


Ensembles d'études connexes

Module 7 Lesson 3 Vocabulary (High Middle Ages)

View Set

NUR 211 Test #3 Added Cards from Mentor Assignment & Lectures

View Set

Intro to Computer Forensics Test 2

View Set