I've encountered a problem when placing a tip on an element in a ForEach
loop. As long as there is only one element in the list the tip will be shown. But if there are more than one element the tip does not appear on iOS and iPadOS.
How do I get the tip to be displayed when several elements are displayed? Is it allowed to use the popoverTip()
modifier in a ForEach
loop or should it be avoided?
Interestingly, it works if you run the attached sample code on macOS. Then the tip is displayed on the “Third” element.
import SwiftUI
import TipKit
struct ContentView: View {
private var elements: [String] = ["First", "Second", "Third"]
let tip = DemoTip()
var body: some View {
NavigationStack {
List {
Section {
ForEach(elements, id: \.self) { element in
Text(element)
.popoverTip(tip)
}
}
}
}
}
}
struct DemoTip: Tip {
var title: Text {
Text("Demo Tip")
}
}
@main
struct TipKitTestApp: App {
init() {
#if DEBUG
Tips.showAllTipsForTesting()
#endif
try? Tips.configure([.displayFrequency(.immediate)])
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}