Complete the code to declare a generic function that returns the input value.
func identity<[1]>(value: [1]) -> [1] { return value }
The generic type placeholder is usually named T by convention. It allows the function to accept and return any type.
Complete the code to declare a generic struct with a property of the generic type.
struct Container<[1]> { var item: [1] }
The generic type placeholder T is commonly used in Swift to represent a generic type parameter.
Fix the error in the generic function declaration by completing the missing generic type placeholder.
func swapValues<[1]>(a: inout [1], b: inout [1]) { let temp = a a = b b = temp }
The generic type placeholder T is used consistently to allow swapping values of any type.
Fill both blanks to declare a generic class with a method that returns the stored value.
class Box<[1]> { var value: [1] init(value: [2]) { self.value = value } func getValue() -> [1] { return value } }
The generic type T is used consistently for the class and initializer parameter.
Fill all three blanks to declare a generic function that swaps two values of any type.
func swapTwoValues<[1]>(a: inout [2], b: inout [3]) { let temp = a a = b b = temp }
The generic type T is used consistently to allow swapping values of the same type.