Swift相对较新,并且与最简单的事情一起挣扎。我希望预先分配一个设置为默认值的结构数组。只要结构不嵌套在另一个类型中,这就可以工作。有任何想法吗?这里被简化例如:嵌套结构类型的Swift数组(count,repeatedValue)
struct PlainStruct
{
var yo:Float = 0.0
}
class WrapperClass
{
struct NestedStruct
{
var yo:Float = 0.0
}
}
// Works just fine
var a = [PlainStruct](count:2, repeatedValue:PlainStruct())
// Error - Cannot call value of non-function type '[WrapperClass.NestedStruct.Type]'
var b = [WrapperClass.NestedStruct](count:2, repeatedValue:WrapperClass.NestedStruct())
感谢
它似乎是一个编译器的bug:http://stackoverflow.com/questions/25682113/why-cant-i-instantiate-an-empty-array-of-a-nested-class – giorashc
嗨,是的好点,但在这种情况下,我确实需要一个Float,没有,我相信它默认为Double。谢谢 – greekgoddj