Swift Slowly: Day 38 - Hacking with Swift 24

It’s the middle of the week and it’s a good time to do some Swift development!

I’m a little struck by one of the things that Paul wrote in today’s exercise.

Albert Einstein once said, “any fool can know; the point is to understand,” and this project was specifically about giving you a deeper understanding of what makes SwiftUI tick. After all, you’ll be spending the next 76 days working with it, so it’s a good idea to make sure your foundations are rock solid before moving on.

Today’s activity is to go back and cement what I’ve learned by accomplishing three challenges. I get most of the changes, but it seems like some of the code has changed over time.

Extension error.

I got the other part of the challenge working, but it seams like the logic for ViewModifier isn’t working with my current release of Xcode/Swift.


Update!


Another user let me know that .fontWeight is only on Text. I was really preoccupied that the challenge needed to work on views. I handled this by having multiple methods; one for Text and another for Content.

struct Title: ViewModifier {
    
    func body(text:Text) -> some View {
        text
            .font(.largeTitle)
            .fontWeight(.black)
            .foregroundColor(.white)
    }
    
    func body(content:Content) -> some View {
        content
            .font(.largeTitle)
            //.fontWeight(.black)
            .foregroundColor(.white)
    }
}
Mandaris Moore @mandaris