|
The challenge reads:
I was a bit baffled by how 'simple' this sounded and figured it was probably just for us to get some practice with how views and things relate to one another and also just to get some coding practice. So I merely copy-pasted the ScrollView containing the HStack that displays the crew members along with its title
But then I got a compiler error saying that the type Is there anything wrong with my approach? Have I misunderstood the challenge altogether? |
|
Farid wonders if he missed the objective:
If you're testing your boundaries and learning something new, I'd say you get full points for this challenge. Your example is hard to follow without before and after code bits. So my mind went a different way with @twoStraw's challenge
Here's a simple example where I have a complex view, and I break out two pieces of view code into their own SwiftUI views. In this example, I alternate Can you accomplish the challenge and extract pieces into their own SwiftUI views?
Create a Reusable DividerView()Try to think in terms of building a reusable Lego brick. It's a unique piece you can easily snap into a solution and know that it fits perfectly. Here's how I see the Requirements AnalysisWhat are the common properties of a DividerView() ?
Simplify the ComplexView()With this reusable Lego brick, you can simplify the Complex view.
HeadlineView()The next step is to pull out the
Refactored ViewNow that you've created two Lego bricks, you can further simplify the original complex view. Please note: Because these two bricks can be put into their own .swift files, it will be easy to reuse this code in other applications you write. Think about common buttons you might want in different applications. Break your complex views into smaller, specialized Lego bricks. Also note, when you use one of your Lego bricks, you can supply your own customizations, or just rely on the default values. This makes the bricks very flexible.
Hope this helps. Keep coding! |
|
@Obelix Thank you so much for this excellent, detailed example and your in-depth explanations. I was able to play around with this in the Sandbox and I learned a few things. However, my question still stands, which is: When two separate structs (MissionView and CrewView, in this case) independently define an identical struct in a nested manner (MissionView.CrewMember and CrewView.CrewMember, in this case), what is the best approach? Should the common struct definition be extracted into the xyzApp.swift file or is there a better place to define the sub-struct such that we can use and reference it in two different views/files? Thank you again, as always. |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.