Post

Replies

Boosts

Views

Activity

Reply to SwiftUI #Previews: How to populate with data
This is really a more idiomatic way: struct BookProvider: PreviewModifier { static func makeSharedContext() async -> [Book] { let url = Bundle.main.url(forResource: "Curs confirmare RO", withExtension: "pdf")! return await withTaskGroup { tg in for _ in 0..<10 { tg.addTask { return await createBook(for: url, of: CGSize(width: 200, height: 200), scale: 4.0) } } var books: [Book] = [] for await result in tg { books.append(result) } return books } } func body(content: Content, context: [Book]) -> some View { ContentView(books: context) } } #Preview(traits: .modifier(BookProvider())) { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
Reply to SwiftUI: List selection of custom struct
The ForEach should group the two Text views, together, in a common container, like a VStack, in order for both of these views to be treated as one, unique entry:   ForEach(rooms, id: \.title) { room in VStack {                         Text(room.title)                             .font(.title)                         Text(room.description)                             .font(.subheadline) }                 }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’22