Now that TipKit has been released by Apple and should be working on Xcode 15 beta 5, I don't know how to integrate a Tip
with a view?
I have the following code:
import SwiftUI
struct TipKitTestView: View {
var body: some View {
VStack {
Text("Some filler text")
UselessTip()
}
}
}
struct UselessTip: Tip {
var title: Text {
Text("Useless title")
}
var message: Text {
Text("Some useless message that is a bit longer than the title.")
}
}
The compiler does not like me having UselessTip()
inside TipKitTestView
, giving the error: Static method 'buildExpression' requires that 'UselessTip' conform to 'View'
. How can I get the code to compile? I don't know how to make the Tip a View if that makes any sense.
On a side note, what code would make the Tip work within UIKit? I am trying to add Tips to my project with a combination of SwiftUI and UIKit code, so I don't know how to integrate Tips in a project with predominantly UIKit code. Does anyone know how to do that?
Whilst TipKit is predominantly written in SwiftUI, Apple have provided UIKit and AppKit implementations.
To implement a tip in UIKit, you could do something like this:
There is further documentation available from Apple for UIKit implementation via
TipUIView
,TipUIPopoverViewController
, andTipUICollectionViewCell
. I've also written an article which goes into how to integrate TipKit with SwiftUI or UIKit.