-1
這是演示此問題的一些演示代碼。無法附加到結構中的自定義協議數組 - Swift
protocol Test {}
struct Conforms: Test {}
struct Testing {
var t: [Test]
//The following throws an error
t.append(Conforms())
}
如果數組是在Struct之外創建的,我可以追加。但在Struct內部,會發生此錯誤。
它不會「拋出錯誤」。它根本不會編譯。 – matt