两个类:
import UIKit
struct ListSection {
var rows : [ListRow]?
var sectionTitle : String?
}
import UIKit
struct ListRow {
var someString: String?
}
现在当我尝试追加时:
var row = ListRow()
row.someString = "Hello"
var sections = [ListSection]()
sections[0].rows.append(row) // I get the following error:
//Cannot invoke 'append' with an argument list of type (ListRow)'
如果我尝试这样做:
sections[0].rows?.append(row) // I get the following error:
//Will never be executed
如何追加到 section[0]
中的 rows
?
最佳答案
你需要先添加一个ListSection
到sections数组
var sections = [ListSection]()
var firstSection = ListSection(rows:[ListRow](), sectionTitle:"title")
sections.append(firstSection)
var row = ListRow()
row.someString = "Hello"
sections[0].rows!.append(row)
关于ios - Swift:无法使用类型的参数列表调用 'append',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32109100/