|
I'm starting with Swift (coming from front-end) with test projects and have a question about view and view builders For reference: in a front-end framework Vue.js there is a concept of slots and slot props (vuejs org guide/components/slots.html#scoped-slots) Same goes for Svelte (svelte dev docs/special-elements#slot) and also same functionality can be achieved in React For example I have some generic list that has some basic layout and makes some logic (filtration, sorting etc) inside and I want to use it to pass a list and display list items however I want, and if I won't provide a builder, there will be some default view that is specified inside that list Is there any way to achieve such functionality in SwiftUI/UIKit? What I've tried to do is something like the next code, I simplified it to show the general idea
But it won't compile because in ViewWithList I get an error Generic parameter 'Content' could not be inferred But it compiles if I pass all the params as plain arguments list, without a struct, but it may get really messy because there is no way to omit some specific arguments and I have to list them all in closure
|
|
If someone is interested, I've managed to implement similar thing and it looks like this:)
And you can go even further and enchance the default view itself, but I don't know if there any downsides of such approach in terms of performance
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.