我希望數組的結構作爲參數在我的函數中進行更改,如果我想要字符串來更改我把文本:字符串,但是當我想測試時要放什麼:ArrayOfStruct作爲參數?如何獲取多個結構數組的一個函數?
func prizeCsGoArraySetup(arrayToAppend: here i want my struct){
if UserDefaults.standard.object(forKey: "prizeArray") != nil {
let demo = UserDefaults.standard.object(forKey: "prizeArray") as! NSDictionary
if let priArray = demo.value(forKey: "csgo") as? NSArray{
for prizeItem in priArray {
if let prizeVC = prizeItem as? NSDictionary{
let newElement : prize = prize(category: prizeVC.value(forKey: "category") as! String, name: prizeVC.value(forKey: "name") as! String, price: prizeVC.value(forKey: "price") as! Int, image: prizeVC.value(forKey: "image") as! String)
arrayToAppend.append(newElement)
我想爲另外7個數組添加可變結構數組,怎麼做? 我不想整個函數寫7次。
很難說出你在問什麼。你能否將你的代碼減少到能夠說明你的問題的MWE? – Raphael