我创建了一个名为Location
一个结构类型问题与创建结构类型的数组的元素
struct Location {
var XCoor: Int
var YCoor: Int
}
我想创建Location
类型的数组我把它命名为places
var places : Array<Location>
Quesiont:如何为数组创建元素?
我错误的猜测中的两个
places[0](Xcoor: 10, YCoor: 12)// error: cannot call value of non-function type 'Location'
places[0].XCoor = 10
places[0].YCoor = 12 //error: constant 'places' passed by reference before being initialized
如果您需要澄清语法来处理数组,我肯定会推荐[Apple的真正简洁明了的指南](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes。 html#// apple_ref/doc/uid/TP40014097-CH8-ID107)(以及Swift基础的其余部分)。 – Hamish
@ originaluser2感谢您的文档 – SLN