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