0

In CourseViewController I have the following variable:

var courses =  [Course]()

declared at top

I try to segue to CourseViewController, by doing this

   let dc = segue.destination as! CourseListViewController
   dc.courses = items[tag] as! [Course]

Is that the right way to do so? "items[tag] as! [Course]" is this correct?

6
  • 2
    "is this correct?" Did you try running your code? Did your code work? If it did, your code is correct. Commented Feb 12, 2020 at 7:42
  • it doesn't work, that's why I'm asking Commented Feb 12, 2020 at 7:50
  • check whether the response is indeed an array of course. Commented Feb 12, 2020 at 7:52
  • @PotaOnasys did you work that out? Commented Feb 12, 2020 at 8:06
  • What is items? Commented Feb 12, 2020 at 8:08

1 Answer 1

1

If you're sure that the item at that tag would surely be a [Course] then it's absolutely correct. If not, use an if-let or guard to avoid runtime exception

 if let courses = items[tag] as? [Course]{
    dc.courses = courses
 } 

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.