Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Swift:如何从数组中的struct访问特定数据?_Arrays_Json_Swift_Struct_Tableview - Fatal编程技术网

Arrays Swift:如何从数组中的struct访问特定数据?

Arrays Swift:如何从数组中的struct访问特定数据?,arrays,json,swift,struct,tableview,Arrays,Json,Swift,Struct,Tableview,} } } 在此代码行“text\u here?.text=data[indexPath.row].properties.timeseries.description”。我不能再详细说明了;“text\u here?.text=data[indexath.row].properties.timeseries.data.instant.details.air\u sea\u level.description” 所以我的问题是如何处理数组中声明的数据,以便指定其背后的数据?如上面的代码示例所示。首

}

}

}

在此代码行“text\u here?.text=data[indexPath.row].properties.timeseries.description”。我不能再详细说明了;“text\u here?.text=data[indexath.row].properties.timeseries.data.instant.details.air\u sea\u level.description”


所以我的问题是如何处理数组中声明的数据,以便指定其背后的数据?如上面的代码示例所示。

首先尝试订阅timeseries数组

struct Data: Decodable {
    let instant: Instant
   // let next_1_hours: Next_1_hours
    //let next_6_hours: Next_6_hours
    //let next_12_hours: Next_12_hours

}

struct Instant: Decodable {
    let details: Details
}

// MARK: - Details
struct Details: Decodable {
    let air_pressure_at_sea_level: Double
    let air_temperature: Double
    let cloud_area_fraction: Double?
    let cloud_area_fraction_high: Double?
    let cloud_area_fraction_low: Double?
    let cloud_area_fraction_medium: Double?
    let dew_point_temperature: Double?
    let fog_area_fraction: Double?
    let relative_humidity: Double
    let ultraviolet_index_clear_sky: Double?
    let wind_from_direction: Double
    let wind_speed: Double
}

这就是声明结构、初始化结构和访问结构属性的方法。可以将相同类型的结构存储在中,然后使用索引访问元素

struct Resolution {
    var width = 0
    var height = 0
}
let someResolution = Resolution()
print("The width of someResolution is \(someResolution.width)")
// Prints "The width of someResolution is 0"

谢谢你,我在找这样简单的东西。成功了!
struct Timeseries: Decodable {
let time: String
let data: Data
struct Data: Decodable {
    let instant: Instant
   // let next_1_hours: Next_1_hours
    //let next_6_hours: Next_6_hours
    //let next_12_hours: Next_12_hours

}

struct Instant: Decodable {
    let details: Details
}

// MARK: - Details
struct Details: Decodable {
    let air_pressure_at_sea_level: Double
    let air_temperature: Double
    let cloud_area_fraction: Double?
    let cloud_area_fraction_high: Double?
    let cloud_area_fraction_low: Double?
    let cloud_area_fraction_medium: Double?
    let dew_point_temperature: Double?
    let fog_area_fraction: Double?
    let relative_humidity: Double
    let ultraviolet_index_clear_sky: Double?
    let wind_from_direction: Double
    let wind_speed: Double
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let  cell = UITableViewCell(style: .default, reuseIdentifier: nil)
    
    text_here?.text = data[indexPath.row].properties.timeseries[*index*]..
    
    return cell
struct Resolution {
    var width = 0
    var height = 0
}
let someResolution = Resolution()
print("The width of someResolution is \(someResolution.width)")
// Prints "The width of someResolution is 0"
let resolutions = [Resolution]()
resolutions.append(someResolution)
let myResolutionWidth = resolutions[0].width