gpt4 book ai didi

ios - 在 Swift 中接受多种结构类型的函数

转载 作者:行者123 更新时间:2023-11-28 06:42:37 25 4
gpt4 key购买 nike

<分区>

我试图将两个不同的结构(继承自同一协议(protocol))传递到一个结构初始化方法中,但出现以下错误:

Cannot convert value of type '[TopContentModel]' to '[TopModel]'

这是我的代码:

protocol TopModel {

}

struct TopContentModel: TopModel {
var type: TableType?
var contentType: ContentType?
var title : String?
var total: Float?
}

struct TopPlatformModel: TopModel {
var platform: PlatformType?
var total: Float?
var type: TableType?
}

struct ChartInfo {
var title: String?
var type: ChartType?
var prefix: String = ""
var labels: [String]?
var values: [Float]?
var list: [TopModel]?
var formatter: NSNumberFormatter?
var special: String?
var secondSpecial: String?
var color: String?
}

var topEarningData = [TopContentModel]()

ChartInfo(title: "Top Earning Assets", type: .TopContent, prefix: "$", labels: nil, values: nil, list: topEarningData, formatter: nil, special: nil, secondSpecial: nil, color: "#37e0af")

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