Why does PKPass take an error pointer?
Asked Answered
S

0

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?

Solus answered 10/11, 2015 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.