Error when use RMStore in swift

518 Views Asked by At

I wanna use RMStore to implement in-app purchase. My project is coding with swift, so I use cocoapod to add RMStore Framework and add a bridge file to make it work in swift. But error occured as I using RMStore.

in bridge header file, I add this:

#import "RMStore.h"

in swift model, I use like this:

func fetchAvalibleProducts()
{
    RMStore.defaultStore().requestProducts(IAPProductsIDs as Set<NSObject>, success: {
        (products, invalidProducts) in
        self.IAPProducts = products as! [SKProduct]}, failure: {error in Utils.error(error)})
}

There is no error when I was coding, but error occured when compiled, error message is like this:

IAPTableViewController.swift:31:9 - line:31:9] typerepr='RMStore')0  swift                 0x000000010f920edb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010f92161b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff835fcf1a _sigtramp + 26
3  swift                    0x000000010dbb0425 swift::Lowering::TypeLowering      
const* swift::CanTypeVisitor<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering const*>::visit<>(swift::CanType) + 549

I've no idea what's wrong here.

1

There are 1 best solutions below

0
Romuald On

No real idea why it's not working, but the correct syntax for swift2 is:

func fetchAvalibleProducts()
{
    RMStore.defaultStore().requestProducts(IAPProductsIDs, success:  {
        (products, invalidProducts) in
        self.IAPProducts = products as! [SKProduct]
        }, failure:  {
            error in print(error)
    })
}