Complete the code to declare a protocol with an associated type named Item.
protocol Container {
associatedtype [1]
}associatedtype is followed by the name of the associated type, which in this case is Item.Complete the code to declare a function in the protocol that returns an element of the associated type.
protocol Container {
associatedtype Item
func getItem() -> [1]
}Item, so the return type must be Item.Fix the error in the struct declaration that conforms to the protocol with an associated type.
struct Box: Container {
typealias [1] = String
func getItem() -> String {
return "Hello"
}
}Fill both blanks to complete the generic function that accepts any Container and returns its item.
func fetchItem<C: Container>(from container: C) -> [1] { return container.[2]() }
Fill all three blanks to define a protocol with an associated type and a property of that type.
protocol Storage {
associatedtype [1]
var [2]: [3] { get set }
}