作者:Turkey小白 | 来源:互联网 | 2023-12-10 15:09
Iamtryingtocreateanarrayofstructinstanceslikethis:我试图创建一个这样的struct实例数组:letinstallers:
I am trying to create an array of struct instances like this:
我试图创建一个这样的struct实例数组:
let installers: [AnyObject] = [Homebrew(), Ls()]
But I get this error:
但我得到这个错误:
value of type 'Homebrew' does not conform to expected element type 'AnyObject'
When I give the array no type, I get an ambiguous type error and that it needs more context.
当我给数组没有类型时,我得到一个模糊的类型错误,它需要更多的上下文。
Is it possible to accomplish what I am trying to do?
是否有可能完成我想要做的事情?
I Googled all over, but I can't find anything.
我用Google搜索,但我找不到任何东西。
3 个解决方案