Ray Wenderlich Course - Second SwiftUI App Part 1

Here we are now! Haven't been able to code for a few days. A quick entry here - around 20 minutes, then some proper time tomorrow! Rather than play around with the SwiftUI view stuff, I feel like cracking on with another Ray course. There's plenty of content on RW.com so I want to get stuck in!
*Entry ends up going over two days!

Start Time - 12:01

I struggled with this 'To-do' app before. I want to have another crack with it as it looks updated with UI even though the overall rating (3.4 out of 5) isn't great.

The dude's name is Jessy Catterwaul. He looks a little like the Joker!

There will be challenges etc. along the way.

Models

A point about copyright statements - something to bear in mind if/when working for a specific company.

A bit about copying a p-list into the main folder. Done.

Models - created a Swift file. This is where the data model will go. Another Swift file created with a class.

OK challenge time - nearly there for now!

class TaskStore {
    var tasks = [ "Brush teeth",
                  "Get cash",
                  "Do this",
                  "Do that",
                  "More of this",
                  "Less of that"
        ].map { Task(name: $0)}
    
    

}

So that challenge was way too hard! Anyway, this was good to recap how to use map on arrays. Creating a custom array is very syntax heavy so it makes total sense to transform it afterwards. 

Cool, going to stop there for now, will continue tomorrow!

Paused at 12:23 (22 minutes so far)

Continued next day at 19:21

So map was a tricky part of the challenge that I wouldn't have known to use at this stage. Yes I've looked at it before and it is cool. But to transform the array like that didn't come to mind. Not to worry - all good experience!

var body: some View {
        List(0 ..< 5) { item in
        Text("Hello, World!")
        }

    }

This basically prints out 5 lots of Hello, World! But we of course want the items for our list. 

Challenge!

Bloody hell that was hard, again. 

var body: some View {
        List(taskStore.tasks.indices) { item in
            Text(self.taskStore.tasks[item].name)
        }
    }

I had the right sort of idea but forgot about the name property. Then I needed self too. 

Identifier



OK so all tasks are going to have this. So that it can be displayed in the list. 

Right, so now the code is less verbose - 

var body: some View {
        
        List(taskStore.tasks, id: \.id) { task in Text(task.name)
            
        }
    }

A protocol can be used here - Identifiable. The requirement for that is to have a property named id. It has to be hashable...something that has a unique hash number....

var body: some View {
        
        List(taskStore.tasks) { task in
            Text(task.name)
            
        }
    }

Dependency Injection

So what is this.... Content view is dependent on task store to function. Task store is a dependency. You need to provide this to the type. DI is the industry standard term. 

Right there is a Scene Delegate file where you can go in and delete what you don't need. Cool - however confusing that is!

Finish Time - 19:57 (36 minutes; 58 in total for the entry)

So an hour into this course and it is mightily confusing. Still, I am seeing it as good practice - getting used to various concepts at once. Like I've said, there is so much on RW.com. But after this course I REALLY must go over an app I've made before and apply what is in SwiftUI from the past two RW courses to apply what I have learned. Yes, that is a must do!

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)