Hacker Hard
Hacker Hard

Reputation: 39

Instance member cannot be used on type ; did you mean to use a value of this type instead?

I have my View defined as below

struct detailPage: View {
    var body: some View {
         VStack() {
              let returnedValue = RNPayPassConnect.canAddPass("Text")
              if (returnedValue) {
                 ProgressView()
              }
         }
    }
}

I need to check the returned value from from canAddPass function, so I have written the code for that, but I am getting an error as

Instance member 'canAddPass' cannot be used on type 'RNPayPassConnect'; did you mean to use a value of this type instead?

Below is my RNPayPassConnect code

@objc(RNPayPassConnect)
class RNPayPassConnect: NSObject {
  let addPassViewController = PKAddPassViewController()
  
  @objc func canAddPass(_ someValue : String) -> Bool {
    let result = PKAddPaymentPassViewController.canAddPaymentPass()
    return result
  }
}

I tried with all possible solutions, but no help, so please can someone help me on this?

Upvotes: 0

Views: 9117

Answers (1)

David Pasztor
David Pasztor

Reputation: 54716

You made canAddPass an instance method, but you are trying to call it on the RNPayPassConnect type rather than on an instance.

You either need to call it on an instance or change it into a static method

Static method:

@objc static func canAddPass(_ someValue : String) -> Bool {
    let result = PKAddPaymentPassViewController.canAddPaymentPass()
    return result
}

Or if you want to keep it an instance method, make sure you store an instance in your view and call it on that:

struct DetailPage: View {
    private let payPassConnect = RNPayPassConnect()

    var body: some View {
         VStack() {
              let returnedValue = payPassConnect.canAddPass("Text")
              if (returnedValue) {
                 ProgressView()
              }
         }
    }
}

Upvotes: 4

Related Questions