Here, We see Swift LinkedIn Skill Assessment Answer. This assessment test consists of 15-20 MCQs to demonstrate your knowledge of your selected skills. MCQs come from different topics – Classes and Structs, Closures and Functions, Control Flow, General, and Types..
List of all LinkedIn Skills Assessment Answer
Swift LinkedIn Skill Assessment Answer
Q1. What is this code an example of?
let val = (Double)6
Code language: JavaScript (javascript)
- A syntax issue✔
- Typecasting
- Assignment
- Initialization
Reference: The Swift Programming Language: Language Guide: The Basics: Constants and Variables
Q2. What is the error in this code?
let x =5guard x ==5 { return }
Code language: JavaScript (javascript)
- The guard is missing the else✔
- Nothing is wrong
- The
guard
is missing athen
- The comparison is wrong
Reference: The Swift Programming Language: Language Guide: Control Flow: Early Exit
Q3. What is the raw/underlying type of this enum?
enumDirection {
case north, south, east, west
}
Code language: JavaScript (javascript)
- There is none✔
-
String
-
Any
-
Int
Reference: The Swift Programming Language: Language Guide: Enumerations: Raw Values
Q4. Why is dispatchGroup used in certain situations?
- It allows multiple synchronous or asynchronous operations to run on different queues.
- It allows tracking and control execution of multiple operations together.
- It allows operations to wait for each other as desired.
- All of these answers.✔
Reference: Apple Developer: Documentation: Dispatch: Dispatch Group
Q5. What is this code an example of?
let val =5print("value is: \(val)")
Code language: JavaScript (javascript)
- String interpolation✔
- String compilation
- Method chaining
- String concatenation
Reference: The Swift Programming Language: Language Guide: Strings and Characters: String Interpolation
Q6. What are the contents of vals after this code is executed?
var vals = [10, 2]
vals.sort { (s1, s2) -> Boolin
s1 > s2
}
Code language: JavaScript (javascript)
- [10, 2]✔
- [2, 10]
- nil
- This code contains an error
Reference: Apple Developer: Documentations: Swift: Array: sort()
Q7. What does this code print?
typealiasThing= [String: Any]
var stuff: Thingprint(type(of: stuff))
Code language: JavaScript (javascript)
- Dictionary<String, Any>✔
- Dictionary
- Error
- Thing
Reference: The Swift Programming Language: Language Reference: Types: Type Identifier
Q8. What is the value of y?
let x = ["1", "2"].dropFirst()
let y = x[0]
Code language: JavaScript (javascript)
- This code contains an error✔
- 1
- 2
- nil
Q9. What is the value of the test in this code?
var test =1==1
Code language: JavaScript (javascript)
- true✔
- YES
- 1
- This code contains an error
Reference: The Swift Programming Language: Language Guide: Basic Operators: Comparison Operators
Q10. What is the value of y?
var x: Int?
let y = x ??5
Code language: JavaScript (javascript)
- 5✔
- 0
- nil
- This code contains an error
Reference: The Swift Programming Language: Language Guide: Basic Operators: Nil-Coalescing Operators
Q11. What is the type of this function?
funcadd(a: Int, b: Int) -> Int { return a+b }
Code language: JavaScript (javascript)
- Int
- (Int, Int) -> Int✔
- Int<Optional>
- Functions don’t have types.
Reference: The Swift Programming Language: Language Guide: Functions: Function Types
Q12. What is the correct way to call this function?
funcmyFunc(_a: Int, b: Int) -> Int {
return a + b
}
Code language: JavaScript (javascript)
- myFunc(5, b: 6)✔
- myFunc(5, 6)
- myFunc(a: 5, b: 6)
- myFunc(a, b)
Q13. The Codable protocol is _?
- A combination of Encodable and Decodable✔
- Not a true protocol
- Required of all classes
- Automatically included in all classes
References:
- Apple Developer: Documentation: Swift: Swift Standard Library: Encoding, Decoding, and Serialization: Codable
- The Swift Programming Language: Language Guide: Protocols: Protocol Composition
Q14. What is the type of value1 in this code?
let value1 ="\("test".count)"
Code language: JavaScript (javascript)
- String✔
- Int
- null
- test.count
Reference: The Swift Programming Language: Language Guide: Strings and Characters: String Interpolation
Q15. When a function takes a closure as a parameter, when do you want to mark it as escaping?
- When it’s executed after the function returns✔
- When it’s scope is undefined
- When it’s lazy-loaded
- All of these answers
Reference: The Swift Programming Language: Language Guide: Closures: Escaping Closures
Q16. What’s wrong with this code?
classPerson {
var name: Stringvar address: String
}
Code language: JavaScript (javascript)
- A person has no initializers.✔
- A person has no base class.
-
var name
is not formatted correctly. -
address
is a keyword.
Reference: The Swift Programming Language: Language Guide: Initialization: Class Inheritance and Initialization
Q17. What is the value of names after this code is executed?
let names = ["Bear", "Joe", "Clark"]
names.map { (s) -> Stringinreturn s.uppercased()
}
Code language: JavaScript (javascript)
- [“BEAR”, “JOE”, “CLARK”]
- [“B”, “J”, “C”]
- [“Bear”, “Joe”, “Clark”]✔
- This code contains an error.
Q18. What describes this line of code?
let val =5
Code language: JavaScript (javascript)
- A constant named val of type Int✔
- A variable named val of type item
- A constant named val of type Number
- A variable named val of type Int
Reference: The Swift Programming Language: Language Guide: The Basics: Type Safety and Type Inference
Q19. What is the error in this code?
extensionString {
var firstLetter: Character="c" {
didSet {
print("new value")
}
}
}
Code language: PHP (php)
- Extensions can’t add properties.✔
- Nothing is wrong with it.
-
didSet
takes a parameter. -
c
is not a character.
Reference: The Swift Programming Language: Language Guide: Extensions: Computed Properties
Q20. didSet and willSet are examples of _?
- Property observers✔
- Key properties
- All of these answers
-
newOld
value calls
Reference: The Swift Programming Language: Language Guide: Properties
Q21. What is wrong with this code?
self.callback = {
self.attempts +=1self.downloadFailed()
}
Code language: PHP (php)
- Use of self inside the closure causes the retain cycle.✔
- You cannot assign a value to a closure in this manner.
- You need to define the type of closure explicitly.
- There is nothing wrong with this code.
Q22. How many values do vals have after this code is executed?
var vals =Set<String> = ["4", "5", "6"]
vals.insert("5")
Code language: JavaScript (javascript)
- Three
- Four
- Eight
- This code contains an error.✔
Reference: The Swift Programming Language: Language Guide: Collection Types: Sets
Q23. How can you avoid a strong reference cycle in a closure?
- Use a capture list to set class instances of weak or unowned.✔
- You can’t, there will always be a danger of strong reference cycles inside a closure.
- Initialize the closure as read-only.
- Declare the closure variable as
lazy
.
Reference: The Swift Programming Language: Language Guide: Automatic Reference Counting
Q24. What is wrong with this code?
iflet s =String.init("some string") {
print(s)
}
Code language: JavaScript (javascript)
- This String initializer does not return an optional.✔
- String does not have an initializer that can take a
String
. -
=
is not a comparison. - Nothing is wrong with this code.
Reference: The Swift Programming Language: Language Guide: The Basics: Optionals
Q25. Which code snippet correctly creates a type alias closure?
- typealias CustomClosure = () -> ()✔
- typealias CustomClosure { () -> () }
- typealias CustomClosure -> () -> ()
- typealias CustomClosure -> () {}
Reference: The Swift Programming Language: Language Reference: Declarations: Type Alias Declaration
Q26. How do you reference class members from within a class?
- self✔
- instance
- class
- this
Reference: The Swift Programming Language: Language Guide: Methods: Instance Methods
Q27. All value types in Swift are _ under the hood.
- Structs✔
- Classes
- Options
- Generics
Reference: The Swift Programming Language: Language Guide: Structures and Classes
Q28. What is the correct way to add a value to this array?
var strings = [1, 2, 3]
Code language: JavaScript (javascript)
- All of these answers✔
- strings.append(4)
- strings.insert(5, at: 1)
- strings += [5]
Reference: The Swift Programming Language: Language Guide: Collection Types: Arrays
Q29. How many times will this loop be executed?
for i in0...100 {
print(i)
}
Code language: PHP (php)
- 0
- 101✔
- 99
- 100
References:
- The Swift Programming Language: Language Guide: Control Flow: For-in Loops
- The Swift Programming Language: Language Guide: Basic Operators: Range Operators
Q30. What can AnyObject represent?
- An instance of any class✔
- An instance of function type
- All of these answers
- An instance of an optional type
Reference: The Swift Programming Language: Language Guide: Type Casting: Type Casting for Any and AnyObject
Q31. What is the value of t after this code is executed?
let names = ["Larry", "Sven", "Bear"]
let t = names.enumerated().first().offset
Code language: JavaScript (javascript)
- This code does not compile. / This code is invalid.✔
- 0
- 1
- Larry
References:
- Apple Developer: Documentation: Swift: Array: enumerated()
- Apple Developer: Documentation: Swift: Array
Q32. What is the value of the test after this code executes?
let vt = (name: "ABC", val: 5)
let test = vt.0
Code language: JavaScript (javascript)
- ABC✔
- 0
- 5
- name
References:
- The Swift Programming Language: Language Guide: The Basics: Tuples
- The Swift Programming Language: Language Reference: Expressions: Primary Expressions: Tuple Expression
Q33. What is the base class in this code?
classLSN: MMM {
}
Code language: CSS (css)
- MMM✔
- LSN
- There is no base class.
- This code is invalid.
Reference: The Swift Programming Language: Language Guide: Inheritance: Subclassing
Q34. What does this code print to the console?
var userLocation: String="Home" {
willSet(newValue) {
print("About to set userLocation to \(newValue)...")
}
didSet {
if userLocation != oldValue {
print("userLocation updated with new value!")
} else {
print("userLocation already set to that value...")
}
}
}
userLocation ="Work"
Code language: PHP (php)
- About to set userLocation to Work… userLocation updated with new value!✔
- About to set userLocation to Work… userLocation already set to that value…
- About to set userLocation to Home… userLocation updated to new value!
- Error
Reference: The Swift Programming Language: Language Guide: Properties: Property Observers
Q35. What must a convenience initializer call?
- A base class convenience initializer
- Either a designated or another convenience initializer
- A designated initializer✔
- None of these answers
Reference: The Swift Programming Language: Language Guide: Initialization: Class Inheritance and Initialization
Q36. Which object allows you access to specify that a block of code runs in a background thread?
- DispatchQueue.visible
- DispatchQueue.global✔
- error example needs to be labeled as throws.
- DispatchQueue.background
Reference: Apple Developer: Documentation: Dispatch: DispatchQueue
Q37. What is the inferred type of x?
let x = ["a", "b", "c"]
Code language: JavaScript (javascript)
- String[]
- Array<String>✔
- Set<String>
- Array<Character>
Reference: The Swift Programming Language: Language Guide: Collection Types: Arrays
Q38. What is the value of things after this code is executed?
let nThings: [Any] = [1, "2", "three"]
let oThings = nThings.reduce("") { "\($0)\($1)" }
Code language: JavaScript (javascript)
- 11212three
- 115
- 12three✔
- Nothing, this code is invalid.
Reference: Apple Developer: Documentation: Swift: Array: reduce(_:_:)
Q39. How would you call a function that throws errors and also returns a value?
- !try
- try?✔
- try!
- ?try
Reference: The Swift Programming Language: Language Guide: Error Handling: Handling Errors
Q40. What is wrong with this code?
protocolTUI {
funcadd(x1: Int, x2: Int) -> Int {
return x1 + x2
}
}
Code language: JavaScript (javascript)
- Protocol functions cannot have return types.
- Protocol functions cannot have implementations.✔
- Nothing is wrong with it.
-
add
is a reserved keyword.
Reference:
- The Swift Programming Language: Language Guide: Protocols: Method Requirements
- The Swift Programming Language: Language Guide: Protocols: Protocol Extensions
Q41. In this code, what are wheels and doors examples of?
classCar {
var wheels: Int=4let doors =4
}
Code language: JavaScript (javascript)
- Class members
- This code is invalid
- Class fields
- Class properties✔
Reference:
- The Swift Programming Language: Language Guide: Structures and Classes
- The Swift Programming Language: Language Guide
Q42. How do you designate a failable initializer?
- You cannot
- deinit
- init?✔
- init
Reference:
- The Swift Programming Language: Language Guide: Initialization
- The Swift Programming Language: Language Guide: Deinitialization
Q43. What is printed when this code is executed?
let dbl =Double.init("5a")
print(dbl ??".asString()")
Code language: JavaScript (javascript)
- five
- 5a
- .asString()✔
- 5
Reference:
- The Swift Programming Language: Language Guide: Basic Operators: Nil-Coalescing Operator
- The Swift Programming Language: Language Guide: Initialization: Failable Initializers
Q44. In the function below, what are these and toThat examples of?
funcadd(thisx: Int, toThaty: Int) { }
Code language: CSS (css)
- None of these answers
- Local terms
- Argument labels✔
- Parameters names
Reference: The Swift Programming Language: Language Guide: Functions
Q45. What is wrong with this code?
for (key, value) in [1: "one", 2: "two"] {
print(key, value)
}
Code language: PHP (php)
- The interaction source is invalid
- The interaction variable is invalid
- There is nothing wrong with this code✔
- The comma in the print is misplaced
Reference: The Swift Programming Language: Language Guide: Control Flow: For-In Loops
Q46. Which of these choices is associated with unit testing?
-
XCTest
- All of these answers✔
-
@testable
-
XCTAssert
Reference:
- Apple Developer: Documentation: XCTest: XCTest
- Apple Developer: Documentation: XCTest: Boolean Assertions: XCTAssert(_:_:file:line:)
- The Swift Programming Language: Language Guide: Access Control: Access Levels
Q47. In the code below, what is width an example of?
classSquare {
var height: Int=0var width: Int {
return height
}
}
Code language: JavaScript (javascript)
- This code contains an error
- A closure
- A computed property✔
- Lazy loading
Reference:
- The Swift Programming Language: Language Guide: Properties: Stored Properties
- The Swift Programming Language: Language Guide: Properties: Computed Properties
- The Swift Programming Language: Language Guide: Closures: Trailing Closures
Q48. What data type is this an example of?
let vals = ("val", 1)
Code language: JavaScript (javascript)
- A dictionary
- A tuple✔
- An optional
- This code contains an error
Reference:
- The Swift Programming Language: Language Guide: The Basics
- The Swift Programming Language: Language Reference: Types
Q49. What is wrong with this code?
var x =5
x =10.0
Code language: JavaScript (javascript)
- You cannot assign a Double to a variable of type Int✔
-
x
is undefined -
x
is a constant -
x
has no type
Reference: The Swift Programming Language: Language Guide: The Basics
Q50. What will this code print to the console?
var items = ["a": 1, "b": 2, "c": "test"] as [String: Any]
items["c"] =nilprint(items["c"] asAny)
Code language: JavaScript (javascript)
- Any
- test
- 1,2,3
- nil✔
References:
- The Swift Programming Language: Language Guide: Type Casting: Type Casting for Any and AnyObject
- The Swift Programming Language: Language Guide: Collection Types: Dictionaries
Q51. What is wrong with this code?
let val =5.0+10
Code language: JavaScript (javascript)
- There is nothing wrong with this code✔
-
val
is a constant and cannot be changed -
5.0
and10
are different types - There is no semicolon
Reference: The Swift Programming Language: Language Guide: The Basics: Type Safety and Type Inference
Q52. How many parameters does the initializer for the Test have?
structTest {
var score: Intvar date: Date
}
Code language: JavaScript (javascript)
- Zero
- This code contains an error
- Two✔
- Structs do not have initializers
Reference: The Swift Programming Language: Language Guide: Initialization
Q53. What prints to the console when executing this code?
let x =try?String.init("test")
print(x)
Code language: JavaScript (javascript)
- nil
- Nothing – this code contains an error
- Optional(“test”)✔
- test
References:
- The Swift Programming Language: Language Guide: Error Handling: Handling Errors
- The Swift Programming Language: Language Guide: The Basics: Optionals
Q54. How can you sort this array?
var vals = [1, 2, 3]
Code language: JavaScript (javascript)
-
vals.sort { $0 < $1 }
-
vals.sort { (s1, s2) in s1 < s2 }
-
vals.sort(by: <)
- All of these answers✔
Reference: Apple Developer: Documentation: Swift: Array: sort()
Q55. DispatchQueue.main.async takes a block that will be
- Not executed
- Executed in the main queue✔
- None of these answers
- Executed on the background thread
Reference: Apple Developer: Documentation: Dispatch: DispatchQueue: async(group:qos:flags:execute:)
Q56. When is deinit called?
- When a class instance needs memory
- All of these answers
- When the executable code is finished
- When a class instance is being removed from memory✔
Reference: The Swift Programming Language: Language Guide: Deinitialization
Q57. How do you declare an optional String?
- String?✔
- Optional[String]
- [String]?
- ?String
Reference: The Swift Programming Language: Language Guide: The Basics: Optionals
Q58. How many times this code will be executed? / How many times will this loop be performed?
for i in ["0", "1"] {
print(i)
}
Code language: PHP (php)
- One
- Two✔
- Three
- This code does not compile
Reference: The Swift Programming Language: Language Guide: Control Flow: For-In Loops
Q59. What does this code print?
let names = ["Bear", "Tony", "Svante"]
print(names[1] +"Bear")
Code language: JavaScript (javascript)
- 1Bear
- BearBear
- TonyBear✔
- Nothing, this code is invalid
References:
- The Swift Programming Language: Language Guide: Collection Types: Arrays
- The Swift Programming Language: Language Guide: Strings and Characters: Concatenating Strings and Characters
Q60. What is true of this code?
let name: String?
Code language: JavaScript (javascript)
- name can hold only a string value.
- name can hold either a string or nil value.✔
- Optional values cannot be
let
constants. - Only non-empty string variables can be stored in the name.
Reference: The Swift Programming Language: Language Guide: The Basics: Optionals
Q61. What is the value of val after this code is executed?
let i =5let val = i *6.0
Code language: JavaScript (javascript)
- This code is invalid.✔
- 6
- 30
- 0
Reference: The Swift Programming Language: Language Guide: The Basics: Type Safety and Type Inference
Q62. What does this code print?
enumPositions: Int {
case first, second, third, other
}
print (Positions.other.rawValue)
Code language: PHP (php)
- 3✔
- 0
- other
- nil
Reference: The Swift Programming Language: Language Guide: The Basics: Raw Values
Q63. What is printed to the console when this code is executed?
"t".forEach { (char) inprint(char)
}
Code language: PHP (php)
- nil
- Nothing, since the code contains an error
- t✔
- zero
References:
- The Swift Programming Language: Language Guide: Strings and Characters: Working with Characters
- Apple Developer: Documentation: Swift: String: forEach(_:)
Q64. What prints when this code is executed?
let s1 = ["1", "2", "3"]
.filter { $0>"0" }
.sorted { $0>$1 }
print(s1)
Code language: JavaScript (javascript)
- []
- [“3”, “2”, “1”]✔
- [321]
- [“1”, “2”, “3”]
References:
- Apple Developer: Documentation: Swift: Swift Standard Library: Collections: Sequence and Collection Protocols: Sequence: filter()
- Apple Developer: Documentation: Swift: Array: sorted()
Q65. What enumeration feature allows them to store case-specific data?
- Associated values✔
- Integral values
- Raw values
- Custom values
Reference: The Swift Programming Language: Language Guide: Enumerations: Associated Values
Q66. In the code below, AOM must be a(n)?
classAmP: MMM, AOM { }
Code language: CSS (css)
- Class
- Protocol✔
- Enumeration
- Struct
References:
- The Swift Programming Language: Language Guide: Inheritance: Subclassing
- The Swift Programming Language: Language Guide: Protocols: Protocol Syntax
Q67. What is the value of numbers in the code below?
let numbers = [1, 2, 3, 4, 5, 6].filter { $0%2==0 }
Code language: JavaScript (javascript)
- [1, 3, 5]
- []
- [2, 4, 6]✔
- nil
Q68. What is the type of vals in this code?
let vals = ["a", 1, "Hi"]
Code language: JavaScript (javascript)
- Array(char)
- [Any]✔
- Array
- [Generic]
Reference: The Swift Programming Language: Language Guide: Type Casting
Q69. How can you extract value to x in tuple vt
let vt = (name: "ABC", val: 5)
Code language: JavaScript (javascript)
- let x = vt.1
- All of these answers✔
- let x = vt.val
- let (
_
, x) = vt
Reference: The Swift Programming Language: Language Guide: The Basics: Tuples
Q70. What is the type of x?
let x =try?String.init(from: decoder)
Code language: JavaScript (javascript)
- String
- String?✔
- String!
- try?
Reference: The Swift Programming Language: Language Guide: Error Handling: Handling Errors
Q71. How many times is this loop executed?
let loopx =5repeat {
print (loopx)
} while loopx <6
Code language: JavaScript (javascript)
- Six
- Zero
- Five
- Infinite✔
Reference: The Swift Programming Language: Language Guide: Control Flow: While Loops
Q72. How many values do vals have after this code is executed?
var vals: Set<String> = ["4", "5", "6"]
vals.insert("5")
Code language: JavaScript (javascript)
- This code contains an error.
- Eight
- Three✔
- Four
Reference: The Swift Programming Language: Language Guide: Collection Types: Sets
Q73. What is the base class in this code?
class LSN: MMM{ }
Code language: CSS (css)
- MMM✔
- LSN
- There is no base class.
- This code is invalid.