1. Adding views and modifiers where they aren’t needed - 1:48 2. Using @ObservedObject when you mean @StateObject - 4:05 3. Putting modifiers in the wrong order - 6:38 4. Attaching property observers to property wrappers - 12:28 5. Stroking shapes when you should stroke borders - 16:19 6. Using alerts and sheets with optionals - 19:18 7. Trying to get “behind” your SwiftUI views - 22:36 8. Creating dynamic views using invalid ranges - 25:03
Thanks for this. As a dev since the 80's, I must say SwiftUI has been one of the trickiest languages I've tried to learn. While crazy powerful, there's so much you need to know up front to make it work. You do a great job explaining things!
It’s really clear your main focus is teaching the community and it’s why you are an invaluable asset to any aspiring SwiftUI developer. You provide time stamps and a quick summary at the beginning easing the bug fixing process for all of us. Thank you so much, Paul, many thanks, from Oxford.
This is by far the best explanation I’ve come across for @State. I’m very much a beginner to coding in general and began working with SwiftUI late last year until I got frustrated back in February and gave up on it. I picked back up with it in April and understanding that @state means the view owns the data makes that property wrapper so much clearer.
This video and the idea behind it is great. would love to see more video like this. common / uncommon issues and what is the best way to handle them, for SwiftUI and Combine.
I love the idea of this video... Reminds me of Pareto 20/80 rule... So, for instance 80% of the problems come from 20% of your mistakes. Identifying those and removing them then leads to disproportionate gains... Very cool frame from which to improve the code, that I haven't seen anywhere else yet. Thanks for sharing
thanks for explain @ObservedObject, and @StateObject, I would use it the other way round or get confused on which one. Maybe you can show next time how different the two function, so people get an detail view of what does what.
Woah, I wanna cry. Thank you thank you for explaining @State and @Observed objects . I couldn’t understand why my fetchDat() networking request request and updates again and again every time I came back from navigation view. I was thinking that it’s because of I’m calling networking request in .onAppear()
Great video, deep explaining. Thanks a million. I've been working my mind around something and have asked about it all over the place with no easy answer so far. I need to build a Text from an array of texts where each time a word is emphasised and should have an image right after, a clickable image that would bring up a meaning on the screen or so. Problem is you cannot concatenate text with a button, or can you? I don't know if you have the time to answer me, but thanks any way for your great videos.
Paul, can you please make a video explaining the difference between components and views? I never know when to separate that in my projects. It ends becoming a huge view, full of modifiers.
Thanks Paul, you nailed it again, common error number 1 I did a lot with RoundedRectangle, where I only need a color. But one annotation: I think combining PropertyWrappers (like @Published) with Property Observers (like didSet ...) works fine since Xcode 12. Do you disagree?
great video! There is one thing I wanted to ask! I got the case where I got a SF Symbol and I attach a continuous animation to it like: Animation.linear(duration: speed).repeatForever(autoreverses: false) I get new speed values from my model in the view, but the animation is only changing if I restart the app. It does not update even I print the value of speed and indeed it does change, the animation keeps the original value of speed throughout. What I am doing wrong conceptually here I wonder?
that thing where every new view modifier wraps view into another view - doesn’t it have negative impact on performance with more complex UIs ? I’m currenrly thinkimg about approach for complex app which does a lot realtime audio processing (which is done in separate resltime audio thread using mostly plain C code thriugh ObjectiveC wrapper) - i am a bit afraid SwiftUI will have bad impact on performance… is SwiftUI viable to use also for more CPU extensive apps ??
This may be a stupid question, but since Swift is open source is there a way to see the code for .font and see the details @paulhudson is talking about?
Hi Paul. I'm stuck with one question. Can you help me? "isEqual"method and operator "===" identical? Which one to use is a matter of taste or are there nuances?
Around 21:40 you show how to display an alert using `.alert` and the `item` argument instead of `isPresenting`. But that also uses the `Alert` view which is now deprecated. What is the new way to display and alert based on a binding to an optional value instead of a binding to a boolean?
@ObservedObject still works just fine if your @ObservableObject is injected via the initializer for your view; and a strong reference to that object is held elsewhere. So in Paul's example, if he were to use `@ObservedObject var model: DataModel` as a property of `ContentView`, the data model instance could perhaps be created by whichever struct/class is creating `ContentView` (where it would be marked with @StateObject). The main benefit here is that it would allow you to use a single instance of `DataModel` in multiple views. Hope this helps. See here: gist.github.com/neilsmithdesign/ad9fc1a6f5856fdf79ce77a3ab4e3d5c
Not understanding the state view was the biggest difficulty when first learning. Noting that regular variables could change, but by themselves, nothing visually would occur. Make sense of course now as you don't want to tax the system unless a state is changed, but when new to swift you learn things like that. For example, why doesn't the button's new set variable not show up in the text field... well you didn't change the view. Do you have any tutorials on sound events in 14, I have been working with sound clips in my apps, but I feel like the way I am doing it is probably using too many resources and makes the app sluggish. Also trying to mix sounds instead of stopping one before starting the next seems tricky.
Great! Thanks! =) What about the problem of a huge EnvironmentObject (many Published vars)? Also, what about navigation in complex project, when some screens could lead to several other screens & there are several UI flows in UX? What about design architectures: MVVM, MVI? What about Coordinator pattern for SwiftUI project with custom NavigationStack & container views (when we just switching some state & in switch block dynamically choosing which view to show)? =))))
Can you please do a video about how you came up with that binding code and explain the syntax as it’s confusing as hell. Swift is NOT easy to read or understand.
So in the case of something like id: \.self; what exactly is the backslash doing? Never quite got that. It's always just been one of those mystical tokens. - I mean, I guess it relates to what the bound of the following .self is, because it's not the encapsulating ContentView struct, but thee aforementioned values in the list, but in like a general abstract sense, what is the \, does it belong just to SwitftUI or is there a general Swift concept that it comes from? Cheers
Great question! The backslash signals a Swift key path, and you can find out more about them here: www.hackingwithswift.com/example-code/language/what-are-keypaths
@@twostraws If you squint it almost looks like a form of reflection, but I assume behind the scenes when compiled this just acts a bit like a pointer or something like that
Hello, Paul, thanks a lot! Without you, I would be entirely lost. As always, everything just in time ;-) Still just wondering about this strange screen position (@11:17) of x: 150, y: 150…, I would have expected the x-position to be much more far off… Is it, because it takes the middle of the "Hello, World!" string as the position? See you ;-)