Search code examples
iosswifttipkit

Swift TipKit: Cannot convert value of type 'Bool' to expected argument type 'Tips.Parameter<Bool>'


I took this example almost literally from Apple's TipKit Parameter documentation https://developer.apple.com/documentation/tipkit/tips/parameter

import TipKit

@available(macOS 14.0, iOS 17.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *)
struct TestStruct {
    @Parameter
    static var testParameter: Bool = true
}

@available(macOS 14.0, iOS 17.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *)
struct TestTip: Tip {
    
    var title: Text {
        Text("TestTip")
    }
    
    var rules: [Rule] {
        #Rule(TestStruct.testParameter) {
            $0 == false
        }
    }

}

problem: in line

#Rule(TestStruct.testParameter) {

The compiler complains

Cannot convert value of type 'Bool' to expected argument type 'Tips.Parameter'

Any idea what I'm doing wrong?

Xcode 15.3, the project targets iOS 16 and newer


Solution

  • $0 appears to be of type Tip.Parameter, but you are testing it against a Bool, hence the error.

    The docs at https://developer.apple.com/documentation/tipkit/tips/rule suggest it should be written:

    #Rule(TestStruct.$testParameter)
    

    (You're right, it appears the docs at https://developer.apple.com/documentation/tipkit/tips/parameter are wrong. There used to be a way to leave feedback on the docs, but I'm not seeing it now.)