Solving “FriendFace” – 100 Days of SwiftUI Day 60 Challenge

Last Thursday I officially joined Apple’s App Developer Program so although I’m anxious to start rolling out some of the apps that I’ve started putting together for now I’m still developing my skills.

I’ve been learning iOS app development through Paul Hudson’s wonderful 100 Days of SwiftUI and I just finished the Day 60 Challenge — Friend Face. I’m posting my work here in order to share my process and solidify my thinking.

I started by identifying the fields I would need from the JSON sample data. As you can see, the fields for each user include:

  • id
  • isActive
  • name
  • age
  • company
  • email
  • address
  • about
  • registered
  • tags
  • friends

The “tags” and “friends” fields are both embedded in arrays and I’ve incorporated these into the model. I’ve also added a closure that makes a computed property which formats the date. Even though friends are included as an array in the User struct, I made a separate struct to define a single Friend. This could have been made into a separate file for organization’s sake but it’s small so I just kept them together.

I wanted to be able to click on a given user’s friends and have the friend profile open up in a new view but I needed to be able to access the list of users on more than one view so I used the @EnvironmentObject variable to access the data from both ContentView and UserDetailView.

Friend Face – ContentView.swift

I used something like Text(“user.[field]”) for each of the fields except for user.registered which I substituted in the computed value that is stored in user.formattedDate so that I would get a date which is easier to read.

Friend Face – UserDetailView.swift

Friend Face – Friend_FaceApp.swift

And with that I have a working app that runs off of live data from the Internet.

I’ve uploaded the code for Day 60 on GitHub.