我想在我的函数中更改struct作为参数的数组,如果我想要String更改我把text:String,但是当我想要测试时要放什么: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个数组添加可更改的struct数组,怎么做? 我不想写整个功能7次。
答案 0 :(得分:0)
很容易
func prizeCsGoArraySetup(arrayToAppend: [MyStruct] )
答案 1 :(得分:0)
我找到了答案,我需要在之前使用。
func prizeArraySetup( arrayToAppend: inout [prize], forKeyText: String )