升级到 Swift 2 后如何修复 IAP 代码?

How can I fix IAP code after upgrading to Swift 2?

我收到一条错误消息“无法使用类型为‘(productsIdentifier: Set)’的参数列表为类型 'SKProductsRequest' 调用初始值设定项,我仍在尝试学习语法更改。有什么帮助吗?

 if(SKPaymentQueue.canMakePayments()) {

            let productID:NSSet = NSSet(objects: "com.organization.appname.iap")
            let request: SKProductsRequest = SKProductsRequest(productIdentifier: productID as Set<NSObject>)

            request.delegate = self
            request.start()
        }

将其转换为 Set<String>,它将正常工作。

这是新代码:

let productID:NSSet = NSSet(objects: "com.organization.appname.iap")
let request: SKProductsRequest = SKProductsRequest(productIdentifiers: (productID as! Set<String>))

2.0 的语法已更改:

// request information about products for your application
@available(iOS 3.0, *)
public class SKProductsRequest : SKRequest {

    // Set of string product identifiers
    @available(iOS 3.0, *)
    public init(productIdentifiers: Set<String>)  //Set<NSObject> will not work anymore

    @available(iOS 3.0, *)
    unowned(unsafe) public var delegate: SKProductsRequestDelegate?
}