问题
I have a struct called Item
and wish to populate its variables.
struct Item {
var title: String
var others: [String]
}
Programs
is an array of all the Item
’s created.
var Programs = [Item]()
I created a struct Item
by the following:
var entered = Item(title: hello1, others: ["hello2"])
The problem is that when I go to print the list of Items
, the programs array is empty
print(Programs)
回答1:
You need to append it
print("Before :",programs)
let entered = Item(title: hello1, others: ["hello2"])
programs.append(entered)
print("After:",programs)
来源:https://stackoverflow.com/questions/59383482/struct-not-being-populated