Complete the code to declare a function that returns some View.
func makeView() -> [1] { Text("Hello") }
The some keyword declares an opaque return type, meaning the function returns a specific type conforming to View but hides the exact type.
Complete the code to declare a variable with an opaque type conforming to Equatable.
var value: [1] = 5
Using some Equatable declares an opaque type that conforms to Equatable, hiding the exact type but guaranteeing conformance.
Fix the error in the function return type to use opaque types correctly.
func getNumber() -> [1] { return 42 }
The function should return some Numeric to use an opaque type conforming to the Numeric protocol, hiding the exact type.
Fill both blanks to create a function returning an opaque type conforming to CustomStringConvertible.
func describe() -> [1] { return [2](value: 10) } struct Wrapper: CustomStringConvertible { var value: Int var description: String { "Value is \(value)" } }
The function returns some CustomStringConvertible to hide the exact type but guarantee protocol conformance. The returned value is a Wrapper instance.
Fill all three blanks to create a dictionary comprehension with opaque types and a condition.
let filteredLengths = ["apple", "banana", "cherry"].reduce(into: [:]) { dict, word in if word.count [1] 5 { dict[word] = word.count [2] 2 } } func makeOpaque() -> [3] { return filteredLengths }
The condition checks if the word count is greater than 5. The dictionary value is the word count multiplied by 2. The function returns an opaque type some Collection.