0

I'm learning Swift and I'm wondering how can I create a data structure with multiple values and pass descriptions values from UITableViewController to another viewController? I have tried like this


   struct faculty {
        var name = String()
        var descriptions = (String)[]
   }
   let faculties = [name: "Faculties", description: ["Study1", "Study2"]]

I have successfully managed to list an array ["Test1", "Test2"] in tableView.

1
  • 1
    The short-hand for an Array type in Swift is [String] (for an array of strings), which is just short for Array<String>. Commented Jun 13, 2022 at 18:54

1 Answer 1

1

There are a couple of issues

  • An empty string array is [String]().
  • description is not equal to descriptions.
  • An instance must be created with Type(parameter1:parameter2:).
  • And structs are supposed to be named with starting capital letter.

struct Faculty {
     var name = String()
     var descriptions = [String]()
}

let faculties = [Faculty(name: "Faculties", descriptions: ["Study1", "Study2"])]

However default values are not needed. This is also valid

struct Faculty {
     let name : String
     var descriptions : [String]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.