简体   繁体   中英

Appending an array inside a struct - Swift 2.0

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?

这个怎么样:

questions.append(Question(title: ["extra value"], additionalInfo: nil, answers:["answer"]))

不知道附录中还有其他questions吗,应该吗

self.routines.append(Question(title:["extra value"], additionalInfo: nil, answers:nil))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM