Today we embark on a new project called Moonshot! Today we go over Resizing images with
We first learned how to display large images with
struct ContentView: View {
var body: some View {
VStack{
GeometryReader { geo in
Image("Example")
.resizable()
.frame(width: geo.size.width)
}
}
}
}
This produces a different result than changing the aspect ratio to
We are going to be loading two types of data from JSON. Provided with the project are two files containing astronauts and descriptions of their work. The second is a list of all the Apollo missions. We create structs for each data type, so it is easier to decode in the next lesson. Each struct will need items to conform to
struct Astronaut: Codable, Identifiable {
let id: String
let name: String
let description: String
}
as we look to decode mission data, a more complex struct is needed to handle crew roles and crew members for each Apollo mission.
This marks the first time we use generics in a project. adding
extension Bundle {
func decode<T: Codable>(_ file: String) -> T {
guard let url = self.url(forResource: file, withExtension: nil) else {
fatalError("Failed to locate \(file) in bundle.")
}
guard let data = try? Data(contentsOf: url) else {
fatalError("Failed to load \(file) from bundle ")
}
let decoder = JSONDecoder()
let formatter = DateFormatter()
formatter.dateFormat = "y-MM-dd"
decoder.dateDecodingStrategy = .formatted(formatter)
guard let loaded = try? decoder.decode(T.self, from: data) else {
fatalError("failed to decode \(file) from bundle")
}
return loaded
}
}
Today we started building the
Swift has a method for handling arrays called
A weird bug in the
Text(self.astronaut.description)
.padding()
.layoutPriority(1)
Challenge one can be accomplished by adding this code just below the image on the mission view
Text(self.mission.formattedLaunchDate)
.font(.headline)
we have already pulled the data in creating the main
On the project quiz, I scored a respectable 83%. I am incredibly pleased with my learning so far in this program and look forward to the next project.
A Whole new project, to infinity and beyond!!
INSERT GIF HERE
Today we start covering drawing in SwiftUI. “SwiftUI makes high-performance drawing easy,” Paul writes. I’ll be the judge of that good sir. All jokes aside, I think it is imperative to learn how SwiftUI draws shapes and interacts with
SwiftUI allows us to draw paths with ease, this can be done by using a
Path { path in
path.move(to: CGPoint(x: 200, y: 100))
path.addLine(to: CGPoint(x: 100, y: 300))
path.addLine(to: CGPoint(x: 300, y: 300))
path.addLine(to: CGPoint(x: 200, y: 100))
}
as you can probably guess, there is a problem here. Yes, this will draw out the triangle that the lesson teaches; however, locations can change. Using hardcoded
We can use Shapes to solve for that inconvenience and reusability. The code outlined that was outlined to create the triangle now looks like this:
struct Triangle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: rect.midX, y: rect.minY))
path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.midX, y: rect.minY))
return path
}
}
And to daw the trinagle we can use this:
Triangle()
.fill(Color.blue)
.frame(width: 300, height: 300)
because we are using
Today, we learned more about drawing and how to manipulate shapes via
We created a circle that cycles through various colors and hues. When drawing a
With SwiftUI, we have great control over how a view is rendered, allowing us to apply blurs and other filters. like adding the
Today we bring back animating shapes! We are animating shapes that we are creating. We learn how to animate shapes that are simple and complex in style. This is done with
This was another technical project where we didn’t create any new content but learned new skills. I never looked into older animating interfaces or
Today is a milestone day, where we look back and reflect on the projects that I have embarked on and written about for the past week and a half. There was some essential learning along the way, and I feel confident in all of the things I learned in these past three projects.
This week has been a lot of fun. I learned so much about how SwiftUI draws views and a bit of US history. I am not feeling the strain of last week’s projects this week. I look forward to more complex, more extensive projects in the future!