Vote count:
0
This example Swift code does not compile if SomeClass is defined as struct. The compiler says: @value $T6 is not identical to (String, Proto)
However, the compiler does not complain if SomeClass is a class.
Why?
public protocol Proto {
func hello(value:Int)
}
public struct SomeClass {
var map = [String:Proto]()
public func store (key:String, value:Proto) {
map[key] = value // That does not work if SomeClass is a struct
}
}
asked 20 secs ago
Swift - store values in map. Different behaviour in structs vs classes
Aucun commentaire:
Enregistrer un commentaire