gpt4 book ai didi

ios - 从数据/模糊使用中获取值(value)

转载 作者:行者123 更新时间:2023-11-30 14:10:48 26 4
gpt4 key购买 nike

class Data {
class Entry {
let filename : String
let heading : String
let referenceville: String
init(fname : String, heading : String, referenceville : String) {
self.heading = heading
self.filename = fname
self.referenceville = referenceville
}
}

let places = [
Entry(fname: "bordeaux.jpg", heading: "Heading 1", referenceville : "bordeaux"),
Entry(fname: "lyon.jpg", heading: "Heading 2", referenceville : "lyo
n"), Entry(fname: "tours.jpg", heading: "Heading 3", referenceville : "tours"),
]

subscript(index: String) -> NSArray {
switch index {
case "places" : return places
case ...
default: return []
}

在 Data 类中,会有很多地方(places1、places2、places3,...)。我想取回值(value)标题。我已经完成了以下代码,但它不起作用。它返回标题的不明确使用。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell2 = tableView.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as! CircuitsTableViewCell

let key = "places"
let data = Data()
var entry: AnyObject = data[key][indexPath.row]
println(entry.heading)
return cell2
}

但是如果我直接将变量设置为固定值,它就可以工作。但我需要使用一个变量。它想念我一些东西,但我不知道是什么。

var entry = data.places[indexPath.row]
println(entry.heading)

最佳答案

正如您所知,places 数组中的项目类型始终为 Entry,因此显式转换该项目

var entry = data[key][indexPath.row] as! Entry

关于ios - 从数据/模糊使用中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31795566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com