Reputation: 1581
I have a struct
struct Question {
let title: [String]
let additionalInfo: String?
let answers: [String]
}
additionally i have created an array with struct object's values like so
var questions = [
Question(title: ["What is this color", "Looks like orange"], additionalInfo: nil, answers: [
"Blue",
"Red"
]),
Question(title: ["Some random question", "some random question detail"], additionalInfo: "additional info", answers: [
"London",
"Liverpool"
]),
Question(title: ["Some random question 2", "Some random question detail 2"], additionalInfo: nil, answers: [
"some answer 1",
"some answer 2"
])
]
I've been playing around a little and that's what i came up with
var routines = [questions]
self.routines.append(questions(Question(title: "extra value", additionalInfo: nil, answers:nil)))
The problem is - it doesn't work.
What is the proper way of inserting a value inside the already existing array wrapped in a struct?
Upvotes: 0
Views: 1287
Reputation: 26907
How about this:
questions.append(Question(title: ["extra value"], additionalInfo: nil, answers:["answer"]))
Upvotes: 3
Reputation: 11597
not sure what that extra questions
is doing in the append, shouldnt it be
self.routines.append(Question(title:["extra value"], additionalInfo: nil, answers:nil))
Upvotes: 1