Scott iOS journal

Skipping around a little bit.

Working on the database module. Activity 9 - reading data. Hard coding the document id values. Not sure how to extract the values for name and company when going thru the documentID.

Hello Pratham,

I saw your email you sent me. Perhaps we can continue discussion of Texas there. I would like the journal to be related to the topic on the header.

Thanks for your understanding.

  • Scott
1 Like

Oh yeah definitely, I totally understand that. You are completely right.

Changed gears again. Working thru the iOS foundations - module 5 - Quiz app.

warning message

let array = try decoder.decode([Question].self, from: data)

Class ‘JSONDecoder’ requires that ‘Question’ conform to ‘Decodeable’

Not sure what that means.

Checked my spelling. Seems fine. Noticed that the decode part of the statement does not change to purple color.

Checked thru the video and compared it to my typed code. Seems fine. Will try it again later.

Do you need help on the Card Match Game? If so, what is it that you need help? What is that you are stuck on?

I think I just need to go thru it again. Each time I go thru the card match game I get a little more out of it. Waiting for the ah ha moment where everything clicks. Feel like I am getting closer but missing something.

Changed the names of the variables to see what breaks and what error messages I get. Still having trouble with the concept of unwrapping and knowing when it is already wrapped. Trying the analogy of cardboard boxes inside of other cardboard boxes to see if that helps.

As soon as I come up with a intelligent question I’ll post it here. Thanks for your offer of help.

iOS foundations - quiz app

Errors.

Class ‘JSONDecoder’ requires that ‘Question’ conform to ‘Decodable’
Errors thrown from here are not handled
Initialization of immutable value ‘data’ was never used; consider replacing with assignment to ‘_’ or removing it.

Error appears on code line

let array = try decoder.decode([decode([Question], from: data)

Code is below in the QuizModel.swift file.
Code has been manually typed following the video. No cut and paste.
Color of the decode did not change to purple like the video.
Color of the delegate?.questionsRetrieved(array) did not change like the video

Checked the code for typos and plural words. Does not seem to be any problems there.
Running Xcode 11.6 on apple computer.

func getLocalJsonFile() {
// Get bundlepath to json file
let path = Bundle.main.path(forResource: “QuestionData”, ofType: “json”)

    // make sure path is filled out
    guard path != nil else {
        print("Could not find the json data file")
        return
    }
    
    //create url object from the path filled out.
    let url = URL(fileURLWithPath: path!)
    
    do {
    // Get the data from the url
    let data = try Data(contentsOf: url)
        
    // Setup json decoder to decode data into objects
    let decoder = JSONDecoder()
    let array = try decoder.decode([Question], from: data)
        
    // notify the delegate of the parsed objects
    delegate?.questionsRetrieved(array)

    }
    catch {
        // Error: Could not read data at that URL
    }

Try making your Question struct conform to the Codable protocol

Checking…

Typo’s typeos typos.

Changed correctAnswer to correctAnswerIndex in the QuestionData.swift file

Added .self to the let array = try line of code in the QuizModel.swift file

Checked that Question.swift matched the name in QuizModel.swift file.

No compiler errors this time. It is working!!! I feel the ah ha moment.

1 Like

Upgraded to Big Sur and Xcode 12.4. Following the quiz app. What he does in the video does not match what I can do in Xcode 12.4.

Will try to revert back to older version of Xcode.

Downloaded and installed Xcode 12.0. Tried to install earlier version of Mac OS but problems with internet install. Still have Big Sur. The drag function to make the stack view under the view is working. Cannot put the image view above the stack view. Created the image view before the stack view.

Chris has an article titled information information about Xcode 12. Have you read that?

I have flipped thru them. Using version 12.0 In the videos did not say specifically which version he is using.

Screen Shot 2021-02-22 at 10.13.08 AM|532x192

Now I cannot test the quiz app on my iPad. Says something about private and public keys. I will keep on with the tutorials and leave this problem for later. I made a time machine backup before the switch which will hopefully restore this functionality. Unfortunately this likely will kill the drag and drop functionality when I try to the stack view and then add the image view as in the videos.

Next time I think I will not upgrade the OS or Xcode. If you in the Chris Code Community are watching this stick with the previous version of Mac OS(Catalina I think) and Xcode 12. Don’t change like I did. Also if you make time machine backup it only backs up the documents, apps, and user settings. It does not back up the OS to the one you were using. Not sure if I forgot to click an option. I was expecting a complete image of the computer before the OS and Xcode changes.

I am disappointed this is not the case.

Changed some of the variable names to check how they relate to the code and what breaks when it is renamed.

Getting the error

Thread 1: “unable to dequeue a cell with identifier AnswerCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard”

Currently stumped as to what that means.

Traced thru the code. I think it should work but it will not compile. I am missing something.

It says that you need to create a custom cell class for that prototype table view cell.