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

时间:2015-09-19 05:24:15

标签: ios swift in-app-purchase swift2

我收到错误说"无法为类型' SKProductsRequest'调用初始值设定项使用类型'(productsIdentifier:Set)'的参数列表而且我还在尝试学习语法更改。有什么帮助吗?

"\\{1,\\}"

1 个答案:

答案 0 :(得分:4)

将其投射为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?
}