6

I'm trying to implement a complex rule to display a Tip from TipKit.

I'm using the official documentation (https://developer.apple.com/documentation/tipkit/tips/event) as example. But the same exact code doesn't compile and gives me the error "The filter function is not supported in this rule." on the line 0ドル.donations.filter { 0ドル.landmarkName != "Wilbere Bowl" }.count > 3

import SwiftUI
import TipKit
struct ContentView: View {
 var tip = InlineTip()
 var body: some View {
 VStack {
 Image(systemName: "globe")
 .imageScale(.large)
 .foregroundStyle(.tint)
 Text("Hello, world!")
 TipView(tip)
 Button("TIP") {
 InlineTip.didViewLandmarkDetail.sendDonation(.init(landmarkID: 0, landmarkName: "TEST"))
 }
 }
 .padding()
 }
}
struct InlineTip: Tip {
 static let didViewLandmarkDetail = Tips.Event<DidViewLandmark>(id: "didViewLandmarkDetail")
 var title: Text {
 Text("Save as a Favorite")
 }
 var message: Text? {
 Text("Your favorite backyards always appear at the top of the list.")
 }
 var image: Image? {
 Image(systemName: "star")
 }
 var rules: [Rule] {
 // Define a rule based on the interaction.
 #Rule(Self.didViewLandmarkDetail) {
 0ドル.donations.filter { 0ドル.landmarkName != "Wilbere Bowl" }.count > 3
 }
 }
}
struct DidViewLandmark: Codable, Sendable {
 let landmarkID: Int
 let landmarkName: String
}

Sorry, if it's a duplicate. I couldn't find anything related to this error.

HangarRash
16.4k5 gold badges29 silver badges63 bronze badges
asked Feb 16, 2024 at 12:00

1 Answer 1

1

I had the same issue just now.

I figured out, you need to exactly use the syntax provided by the documentation:

[...]
 #Rule(LandmarkDetail.didViewLandmarkDetail) {
 0ドル.donations.filter({ 0ドル.landmarkName != "Wilbere Bowl" }).count > 3
 }
[...]

Note the round brackets in the filter function.

answered Mar 25 at 17:35
Sign up to request clarification or add additional context in comments.

1 Comment

That's ridiculous. They restrict correct syntax due to underdeveloped macros... and that's undocumented, yet advertised as a feature ready to use in the public release of iOS. YEAH

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.