1
我想根據用戶輸入在swift中創建動態結構。在Swift中動態結構創建 - 基於用戶輸入
struct Diagnosis {
var diagName = String() // Name of the diagnosis
var diagSymptoms = [String]() // Symptoms of the diagnosis in a ranked array to identify prevelancy
var diagSpecialization = [String]() // the specializations which would mostly encounter this diagnosis
var diagRank = Int() // the overall rank of the diagnosis
var diagSynonoms = [String]() // the other name thru which the same diagnosis is called/referred.
// func init(diagName: String(),diagSymptoms: [String](),diagSpecialization: [String](),diagSynonoms: [String]())
init(let pasdiagName: String,let pasdiagSymptoms:Array<String>) {
self.diagName = pasdiagName
self.diagSymptoms = pasdiagSymptoms
}
}
var maleria = Diagnosis(pasdiagName: "Maleria",pasdiagSymptoms: ["fever","chill","body pain"])
上面創建結構maleria - 但在未來,我希望能有來自用戶的輸入,併爲輸入字符串
var abc = "typhoid"
let valueof(abc) = Diagnosis()
創建一個結構
的功能價值是我只是把這裏任意地使我的解釋清楚。 我知道我可以在Python中做到這一點,我是新來的迅速。先謝謝您的幫助。
你描述的被稱爲字典... – Wain