0
votes

iam triying to use a NFC Framework, which is in Objective C, I made a bridge Header and converted the call so swift.

but got the error here:

"Cannot convert value of type 'String' to expected argument type 'EInkSizeType'"

Can anyone help.?

        let image = UIImage(named: "nummer27")
                        
        
      let EInkSizeType420 = "EInkSizeType420"
        
     //  [[NFCTagReader sharedSingleton] sendImage:image einkSizeType:EInkSizeType420];];
     //  Converted to Swift 5.2 by Swiftify v5.2.19376 - https://swiftify.com/
      NFCTagReader.sharedSingleton().sendImage(image!, einkSizeType: EInkSizeType420)
        
       
1
The error is clear: The parameter einkSizeType must be an instance of type EInkSizeType (presumably an enum) rather than a string. - vadian
Replace the variable in the last line with . and wait for autocompletion (or press Ctrl+Space). Your option should be there... - Michael

1 Answers

0
votes

The method signature is expecting a value of type EInkSizeType for param einkSizeType:, so the full signature would be:

sendImage(_ image: UIImage, einkSizeType: EInkSizeType)

Without knowing the exact framework, I can only guess the enum would be something like EInkSizeType.EInkSizeType420. Auto-complete should help you with this, simply start typing . as the parameter and a list of possible values should be shown. Therefore, assuming .EInkSizeType420 is the correct enum value your code should look like:

let image = UIImage(named: "nummer27")

 //  [[NFCTagReader sharedSingleton] sendImage:image einkSizeType:EInkSizeType420];];
 //  Converted to Swift 5.2 by Swiftify v5.2.19376 - https://swiftify.com/
  NFCTagReader.sharedSingleton().sendImage(image!, einkSizeType: .EInkSizeType420)

Also, just a tip, in production try not to use ! (forced unwrapping) where possible and opt for ? (optional) unless the intended action for the app is to crash should the value be null. Instead, try to gracefully handle the unexpected case by using guard let ... else { ... }:

func sendImageToNFCTag() {
  guard let image = UIImage(named: "nummer27") else {
       // Show alert dialog that image couldn't be found here
       // ...
       return
  }

  //  [[NFCTagReader sharedSingleton] sendImage:image einkSizeType:EInkSizeType420];];
  //  Converted to Swift 5.2 by Swiftify v5.2.19376 - https://swiftify.com/
  NFCTagReader.sharedSingleton().sendImage(image, einkSizeType: .EInkSizeType420)
}