Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Video Tutorial: iOS 101 Part 4: Storyboards and Segues

Learn how to use storyboards to set up your view controllers, create relationships between them with segues, and refactor them with references.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3716-ios-101-with-swift-2/lessons/5
2 Likes

Thanks for the tutorial .It really helped me a lot

I am having trouble getting the Challenge to build.

I have got near the end and the error I am getting is

/VGTrivia/VGTrivia/ViewController.swift:25:75: Use of undeclared type ‘AnswerDisplayViewController’

&

VGTrivia/VGTrivia/ViewController.swift:26:41: ‘AnyObject?’ is not convertible to ‘UIButton’; did you mean to use ‘as!’ to force downcast?

I can not find any other use of the AnswerDisplayViewController, if I change it to AnswerViewController that causes other errors.

Also I think there is a mistake in the instructions, it refers to

Select the new view controller, bring up the Assistant Editor and make sure AnswerViewController.m is displayed. Then connect the two labels to private outlets in AnswerViewController.m - statusLabel and correctAnswerLabel, respectively.

I think that it should be AnswerViewController.swift, or at least I could not find a .m anywhere.

Some guidance would be appreciated. Thank you

I appreciate it is impractical to be able to debug everyone’s code that does these tutorials.
Could someone please clarify if the line of code in the, Challenge 4 which reads

let answerViewController = segue.destinationViewController as AnswerDisplayViewController

Is correct as it’s giving me an error and I have just copied and pasted that block without changing anything, so it seems odd that the autocorrect (or whatever xcode error correction is called) is highlighting it as incorrect.

Thanks

Well I am a little disappointed with the lack of response. It really breaks your flow if you have to wait days for a reply. Although looking around I see lots of never answered questions, - shame I’m sure people stop paying if they get stuck and can’t get past where they are at.

Hi Heaford … Sorry for the delayed response. The error is being caused because of a cast. At the time this was updated, you didn’t need to wrap your cast in an optional such as

let answerViewController = segue.destinationViewController as AnswerDisplayViewController

Instead, you do something like:

let answerViewController = segue.destinationViewController 
      as? AnswerViewController

Also note, the controller being cast should be a AnswerViewController instead of an AnswerDisplayViewController. I’ve updated the challenge document with these changes. If you get stuck again, feel free to shoot me a message here, or directly at brian@razeware.com.

Cheers!

1 Like

Hello Brian, I have a question regarding the Uber Haxx0r Challenge that you posted in this tutorial.

I googled / stack overflowed / rayWenderliched / appled , but I couldn’t find the right solution to pull the info out of the dictionary in plist and populate the Question objects appropriately.

in my plist (file named Questions.plist), my root object is defined as dictionary, and have 1 object of questions as Array.
in questions array, I have dictionaries that have the keys of question, answer1, answer2, answer3, answer4 and rightAnswer. I filled up all the data. Edit: I just uploaded the screenshot of my plist. the censored parts are just my questions and answers.


here are some codes that I put in ViewController.swift

override func viewDidLoad() {
    super.viewDidLoad()
    var myDict: NSDictionary?
    if let path = NSBundle.mainBundle().pathForResource("Questions", ofType: "plist") {
        myDict = NSDictionary(contentsOfFile: path)
    }
    if let dict = myDict {
       let question1 = dict.objectForKey("questions")?.objectForKey("Item 0")?.allValues
       let question2 = dict.objectForKey("questions")?.objectForKey("Item 1")?.allValues
    }

I am stuck after binding dict to myDict, since I don’t know how to extract the data from plist and put it into Question object. I would appreciate your help in this matter! thank you !

Overall I think this was a good challenge. However the descriptions for steps were a little unclear and required some hunting around to find out how to do it. Helps you learn to hunt around, but also would be nice to have the instructions a bit clearer.

I had random errors “EXC_BAD_INSTRUCTION” when I kept the viewWillAppear code as outlined in the example each time you click on the Another button

    currQuestion = questions[Int(arc4random()) % questions.count]

When I changed the code as follows it works every time

    let index = Int(arc4random()) % questions.count
    currQuestion = questions[index]

Hi itaylorm, did you was able to fix the issue with "EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP, subs… I tried your recommendation but it is not working for me neither. Any help will be appreciated. Thanks.