创建新字符串类型的最佳方法是什么,该类型仅包含特定基类的派生类的名称。例如:如果A是超类,而A1,A2,A3等是派生类,则新类型func setPastCell<T: DataModel>(cell:WeekCell, data_dic:T) {
if let firstModel = data_dic as? FirstDataModel {
print(firstModel.team1_name)
print(firstModel.team2_name)
print(firstModel.status)
print(firstModel.image)
print(firstModel.score)
} else if let secondModel = data_dic as? SecondDataModel {
print(secondModel.team1_name)
print(secondModel.team2_name)
print(secondModel.status)
print(secondModel.image)
print(secondModel.count)
print(secondModel.balance)
}
}
应该只允许以字符串形式分配这些派生类名称。
SubClassName