Skip to content

MattWong-ca/swiftui-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

82 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± SwiftUI Projects

This repo contains a collection of SwiftUI projects I've made!

1. PokΓ©dex

A Pokemon Pokedex that fetches data from a CSV file to display a list of 720+ Pokemons. Each Pokemon has its own profile that shows their types, stats, and an image.

Pokedex ContentView Venusaur Charizard Blastoise Empty search bar Using search bar Volcanion

Views

ContentView: a List is used inside a NavigationView, where each NavigationLink links to a PokemonDetailView of the titled Pokemon. The colored type tags are reusable PokemonTypeViews that are also used in PokemonDetailView. The pokedex array of Pokemon passed in is from the loadCSVData() function in CSVManager (called in PokedexApp). Added a search bar: used a @State searchText property to pass in .searchable(), keeping track of what the user inputs. If a Pokemon's name contains the characters they input, it gets added to a new filteredPokemon computed array of Pokemon objects that return the list of Pokemon shown when searched.

PokemonTypeView: small colored tags that show the Pokemon's type. The Pokemon's type as a string is passed in --> this is used for 1) the text and 2) the different colored backgrounds, which match the appropriately-named colors in Assets (eg. .background(Color(pokemonType))).

PokemonDetailView: view that shows up when a Pokemon in the list is clicked. It displays the Pokemon's properties through HStacks/VStacks in the appropriate Sections.

PokemonImageView: called in PokemonDetailView to display the Pokemon's image. Important fetchImage() used to fetch the image from PokeAPI (only the image URLs they provide are used, didn't get the JSON data back and decode it). It uses a URLSession where the data is passed into a UIImage.

Models

pokemon.csv: contains list of 720+ Pokemons. First 3 lines:

#,Name,Type 1,Type 2,Total,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary
1,Bulbasaur,Grass,Poison,318,45,49,49,65,65,45,1,False
2,Ivysaur,Grass,Poison,405,60,62,63,80,80,60,1,False

Pokemon: the Pokemon object struct, conforming to Identifiable protocol. A Pokemon is an array of Strings, with each String representing 1 attribute (eg. Pokemon = one row in the CSV).

CSVManager: the function loadCSVData() returns an array of Pokemon objects (eg. [["Bulbasaur", "1"], ["Charmander", "2"], ["Squirtle", "3"]]). It takes the file path of the CSV file, turns its content into one giant string, cleans up the rows, separates data into an array of rows (strings), separates each row so each of its properties are a string, then creates a Pokemon and adds it to the array that'll be returned.

Notes

  • I originally used Data(contentsOf: ) but that was synchronous URL loading of the images, which can crash the app / lead to UI unresponsiveness
  • Where I learned to add the images: Stack Overflow
  • Tutorial I followed: Oliver Baumeister

2. Weather App

Weather App that uses CoreLocation to fetch a user's location and the OpenWeather API to fetch the live weather data. Background changes depending on the weather!

WIP Screenshots

MVP MVP

Landing Page + User Flow

Landing Location Loading

Different Cities + Weather Background

Johannesburg Mumbai Rio 2023-09-04 at 4 37 52 PM Nishigocho 2023-08-04 at 3 50 07 PM London 2023-08-04 at 3 48 00 PM Mexico City 2023-08-04 at 3 34 51 PM

3. Hacker News

Hacker News uses the HN Algolia API (hn.algolia.com/api) to fetch a list of front-page articles on Hacker News. The results are returned in a list ordered by the number of points they received.

ContentView 1st WebView 2nd WebView

Views

ContentView: creates an instance of NetworkManager() for fetching API data. At .onAppear, fetchData() is called. The body view uses a NavigationView to go back/forth from article links. Each row in the List is a NavigationLink with a destination set to a DetailView, and text showing the points + article title.

DetailView: the view that pops up when someone clicks an article title. It shows the WebView by instantiating WebView(urlString: url) and passing in the article's URL.

WebView: conforms to UIViewRepresentable protocol in order to use WKWebView. The protocol requires 1) makeUIView which makes the WebKit WebView and turns it to a SwiftUI-compatible WebView, and 2) updateUIView which updates the view with new info from SwiftUI.

Models

NetworkManager: conforms to ObservableObject since UI properties in ContentView are dependent on posts from this class. fetchData() function creates URL() and URLSession() instances, and makes async network request with dataTask() to fetch the API data. JSON data is then decoded and posts is updated with retrieved data.

PostData: a Results struct that imitates the JSON data from the API. Conforms to Decodable since we want to go from JSON --> struct. Results holds a single property hits, an array of Post objects that defines the properties of an article (eg. points, title, etc.).

4. Sweater Shop

The frontend of a ecommerce sweater store.

ContentView ScrollView Empty cart Filled cart CartView

5. Memory Game

Matching cards memory game.

Screenshot Screenshot Screenshot Screenshot

6. MiiCard

Simple digital business card app that displays 3 contact info buttons. Created a ButtonLinkView struct for the contact info buttons to improve code reusability.

MiiCard ContentView

About

πŸ“± Collection of SwiftUI projects I've made!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages