meeting 3: recap & more!
Recap !
These are our main views: SwiftUI files which the user interacts with. These files only contain design and UI components.
This is another view that establishes what all our “Destinations” will look like when we click on them (the image, description, title, etc.)
These are our components, which support our views by adding visual details.
This is a Model, which establishes the logic of each of our “Destination” cards.
Progress !
We’ve set up our ContentView so it displays DestinationsList with clickable Destination cards.
We’ve also finished our DestinationsView so we can see the description for each of our Destinations.
Progress !
Next week we will get started with implementing our Categories page. We will also create a form so users can upload new destinations.
MVVM (Model, View, ViewModel)
DestinationsView is a Model!
DestinationsCard is a View and ViewModel!
Data Binding: The DestinationCard view directly accesses properties of the Destination object passed to it. It binds to the destination parameter to display the name and image of the destination.
Presentation Logic: DestinationCard defines the presentation logic for displaying a destination. It determines how the destination's image and name are presented on the screen, including styling, layout, and handling placeholder images.
It defines the layout of the destination card and how its contents are displayed, making it closer to a ViewModel in terms of responsibilities.
Breaking down the DestinationsModel
Enums, structs, and extensions !
Static Property
A property which belongs to a type and instances of said type can use.
The static properties we will see are:
What is the ID property?
ID uniquely identifies the instances of a type, such as user or person. It’s helpful for indexing through collections, comparing items, and identifying objects.
What’s a Protocol ?
Category Enum
This enum represents categories for destinations.
It conforms to the Identifiable protocol, which means it has an id property that uniquely identifies each case.
CaseIterable is a protocol which allows us to iterate through all values of Category (will be useful later to use print(Category.allCases).
Each case of the enum represents a category (the Strings visited and toVisit).
The id property is implemented to return the raw value of each enum case (which is a string in this case).
This is what the categories will be used for!
Destination Struct
Extension
Allows us to add new functionality to an existing struct (or class, enum, etc.). Uses:
Extension on Destination
Provides a static property all which is an array containing instances of Destination.
This array contains predefined destination objects initialized with our data.
NEXT WEEK
CategoriesView
CategoryView
… and more
View vs NavigationLink vs NavigationView ?
GitHub