Finally, we can work on the collection view itself.After we know what we want to display, we need to tell SwiftUI how to do it.It’s a requirement by ForEach loop to properly identify objects from the given collection. To work with what is coming in the next steps, the objects we want to display need to implement the Identifiable protocol. Fortunately, SwiftUI offers an object called ScrollView, which combined with HStack and some more SwiftUI magic, gives us what we might want. Note: in the following code samples, I will be using some classes (i.e., Pokemon ) that were not declared before – you can refer to this Github repository for their declarations :)Īchieving an object that is horizontally scrollable was quite quick and intuitive. Created by Karol Kulesza, QGrid is a reusable collection view that might be useful for you! And I really wanted that! Stacking & scrollingīefore moving to implement the collection in SwiftUI, I would love to recommend a solution that is already out there. The default component for representing datasets in SwiftUI is a List, which is basically an equivalent of UITableView – so no horizontal scrolling and no custom layouts. Since I wasn’t satisfied with the Apple approach, I did what every other developer would do (after going through StackOverflow) – I started playing with what is out there. The obvious thing to do – play with SwiftUI Luckily, some of us got to ask at the source how to approach it. There is no direct equivalent of our beloved UICollectionView! For me personally, it was quite strange since this control is being used a lot in apps all over the App Store. However, while the excitement was building, some of them quickly noticed that a piece that we all love is unfortunately missing. Otherwise, a good primer on the subject is the WWDC 2019 session number 204 – read this first and then come back here! The missing part of SwiftUIĪfter the announcement, developers from all over the world started digging into the possibilities of SwiftUI and were mostly amazed. This blogpost is meant for people who already have a basic understanding of SwiftUI. Long story short, it’s a declarative framework that can massively reduce the time needed for creating and refactoring views in our apps. During WWDC, Apple announced a brand new framework for creating UI – SwiftUI. June 2019 was mind-blowing for the Swift Developers Community.
0 Comments
Leave a Reply. |