Learn Courses My Dashboard

Scott iOS journal

Yes we have met. It’s just the username that has changed.

Wow! You’ve been busy! I think I got in just early enough that my Xcode version could do everything Chris wanted. Now some of those apps are broken but I’ve moved on and it isn’t a problem. That really sucks you are going through that. I believe that’s one main reason Chris started over with SwiftUI (I have not done any of those yet myself)

I’m curious about your optional problem. My understanding of optional unwrapping is like this: The idea is that Swift wanted a language that wouldn’t allow a variable to crash the app by being empty. So they created optionals to allow empty variables to exist in the program, but will not allow the program to run unless all of them are filled with some data when needed. So we use them to say download some json data Into a model but there’s no guarantee anything will be in that json file. You check if the variable is nil and if it is nil you don’t use it. If it has data then you are free to unwrap the variable! Haha see what I did there

I’m sure that you already knew all that I’m really just trying to find your area of difficulty

Your error about needing an identifier and creating it from a nib I used to get a lot when I started creating tableViews programmatically. If you are in storyboard you just have to make sure your table view has at least one cell template, which you can do by clicking on the table view and raising the cell count to 1. And then you can click on the new cell and put whatever you want for the identifier. Say “cellIdentifier” Then in your code you set up the dequeueReusableCell with identifier “cellIdentifier”

If you are doing it programmatically you can write a bit of code that does this I just can’t remember it right off the top of my head. If you want it I can get it, you might prefer it that way anyways

Is it possible to choose something else? Dumby gives the perception that you are dumb which you are not.

1 Like

I think I have the problem of thinking like a human. The app will crash if it gets nil instead of the expected datatype. What I am looking for is how to protect against nil without having to trace the code back to the origin where it was declared. I don’t know why I have a problem with this. I feel like I am squeezing my round brain into a square computer block. My typos don’t help with this.

I need to think about what you wrote.

I feel like the character in the movie - Where the Heart is. There is a scene in the movie where Natalie Portman is in the library doing some research. She has two paper dictionaries spread on the table. One is a kids dictionary the other is a adult dictionary. She is looking up the words in the adult dictionary and if she didn’t understand it looking up the definition of the word ( from the adult dictionary) in the kids dictionary.

I feel like that. I close to the ah ha moment Chris talks about but still wondering around in the fog and bumping into things.

Yeah, thank you for the kind words at the end. But I don’t think I can change my username to Pratham_Hebbar unfortunately.

Oh ok. I thought you might be experiencing cyber bullying and that is why you decided to change it.

1 Like

Skipping round the modules. Working thru the json examples.

Got error code.

questions retrieved from model

2021-03-12 09:31:40.653324-0700 QuizAppVer021121[1308:84270] *** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], UITableView.m:9037

2021-03-12 09:31:40.661590-0700 QuizAppVer021121[1308:84270] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: '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’

Working thru it. I likely made a typing mistake.

Yep. I made a typo.

In the question.swift file I typed

var answers:[String?]

The correct way is

var answers:[String]?

I only had to retype the project twice, from scratch, to spot my mistake.

Mac productivity note.

Use multiple workspaces.

Press the mission control key on the Mac keyboard. Add a workspace using plus button.

Arrange the applications in full screen to my liking inside those workspaces.

Use mission button to change from screen to screen.

So much better than the command + tab. I got a second monitor and usb c to hdmi converter so I could compare what Chris typed and what I typed. Chris stuff on one screen, my Xcode on the other screen.

This was worth the investment.

Note to self. Tried to drag image view above stack view in module 5 lesson 5. It works if you drag the image view onto the the safe area. I did not get the blue line like I was expecting.

Using Xcode 12.4 and Mac OS 11.2.3

Running thru the match app. Still stuck on the casting and objects. When it says CardCollectionViewCell does that mean the individual cell that has the card image or is it array of objects? When the opacity of the cell is change I was expecting some code to remove the cell from memory…seem like the user cannot see the card cell but it’s still there in memory…

I am missing something. Feel so close to the answer…

Moving to the Quiz app for a while.

I think I am stuck on the concept of the cell template. How does the cell template know I want 15 more cards ( 16 total)? My brain keeps looking for the while loop that sets this up but the dequeueReusableCell does this automatically. I think I am going to try it and change the method and variable names and see what breaks…I need to be able to follow what flows from where. I have got the app to works as coded so I know the code is solid but I would like to modify it to fully understand how it works.

The reusable cell is the template for every card that is required. Each time a cell is required it is created and placed in the required location on the screen. Only enough cells are created to be visible on the screen at any moment. As soon as you begin to scroll the collectionView, the cells at either the top or the bottom that go out of view are reused to display the next card or group of cards that come into view either at the top or the bottom. So the number of cells required overall is pegged to the array count (16) in this case.

The two methods numberOfItemsInSection and cellForItemAt work hand in hand to generate the cards for display. The method numberOfItemsInSection returns the total number of cells that are required based on the number of elements in the array, hence
return cardArray.count
controls the cellForItemAt method which creates each cell and populates it with the back card and the front card.

There is a lot of stuff going on in the background that the collectionView deals with but the methods define what it has to do.

As for modifying it to improve your understanding, I am not sure what you could do that would help. It does take a number of iterations of building a collectionView application to get the hang of it.

Hope that helps.

If not ask more questions.

1 Like

Going thru the module 3 quiz app. Removed some constraints for the label. Get this error when trying to run it.

Thread 1: “[<QuizAppVer021121.ViewController 0x7fdd17006da0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableViewQuestions.”

Looking for syntax errors.

I think it will take a few iterations for me to get the hang of it. Seems to be straight forward. You add a protocol. The protocol has two fixed requirements. You give the protocol those requirement using .count and row/cell for item at parameters. The computer will reserve that amount of memory for the creation of the objects. It creates those objects using the image asset library and the file we selected for that object ( background image) and displays them on the screen. The app scans for input from the user. User clicks on a view element. This keypress is detected by the view controller.swift because it has been named the destination for those events using the delegate/datasource code. Every step must guard against the array , object or variable from being nil. Nil will crash the app unless there is code to handle that event.

Sound about right?

This generally means that there is either a link broken between the storyboard and the ViewController or a left over link in the case of re-creating a link with the correct name.

Select your storyboard ViewController and then have a look at the Connections Inspector panel over on the right to see if there is any marked with an amber triangle. That will indicate that the connection is broken. Example below.

It’s easy to mistakenly simply overtype the outlet name and expect it to work. That’s not the right way to do it. The best way is to place your cursor on the outlet name in your ViewController.swift file, then right click and select Refactor > Rename. This method ensures that the alteration occurs in the both the ViewController.swift file and the storyboard.

Note to self.

Did not have any simulators after Xcode rebuild. Going thru the quiz app. In the video Chris asks to run the app. Looked at the device/simulator list. No simulators listed.

Searched online. No suggestions on what I should try for my particular setup.

Digging around the setup for the app. Noticed that the iOS has up and down arrow in the deployment info section of the project. Clicked on the highest level in the document outline. Screen appear with identity, Deployment info.

Changed from iOS 14 to iOS 13.6

Simulators appear in the drop down now.

I reattached the outlets after deleting the code. Thanks for the explaination Chris. :slight_smile: