9

According to Apple's documentation, initializing a PKPass in Swift requires two elements, the Pass data and an error pointer.

init(data data: NSData,
error error: NSErrorPointer)

According to Apple's Swift documentation, Error Handling paragraph,

In Cocoa, methods that produce errors take an NSError pointer parameter as their last parameter, which populates its argument with an NSError object if an error occurs. Swift automatically translates Objective-C methods that produce errors into methods that throw an error according to Swift’s native error handling functionality.

There is a note though:

Methods that consume errors, such as delegate methods or methods that take a completion handler with an NSError object argument, do not become methods that throw when imported by Swift.

Since the method does not seem to be consuming, but rather, if needed, setting the error using the pointer, it seems to be going against Apple's explanation of error handling. I was expecting code more along the lines of:

  do {
      let modifiedPass : PKPass = try PKPass(data: data)
     } catch let errorCaught as NSError
     {
        print("Error: \(errorCaught.domain)")
    }

What am I woefully misunderstanding, or possibly what is the reason for this apparent mismatch?

dandan78
  • 12,242
  • 12
  • 61
  • 73
Kheldar
  • 5,235
  • 3
  • 29
  • 62

0 Answers0