我有一个具有一些属性、类或结构数组的对象
我想把这些属性放在一个数组中,这样我就可以在 TableDataSource 中轻松访问它们(因为部分、索引路径等)
我试过写这个初始化
var dataStructure = Array<Any>()
var tweet : Tweet?{
didSet{
dataStructure.removeAll()
dataStructure.append(tweet?.media)
dataStructure.append(tweet?.urls )
dataStructure.append(tweet?.hashtags)
dataStructure.append(tweet?.userMentions)
}
}
然后检索它
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
let arr = dataStructure[section] as? NSArray
if arr != nil{
println(arr!)
return arr!.count
}else{
return 0
}
}
但 arr 始终为零
也许是因为我正在投射到 NSArray?但我不能转换为“数组”
media 、 urls 、 hastags 和 userMentions 在“Tweet”类中初始化
public var media = [MediaItem]()
public var hashtags = [IndexedKeyword]()
public var urls = [IndexedKeyword]()
public var userMentions = [IndexedKeyword]()
所以它们是非常普通的数组