Swiftystorekit: Add public initialiser for internal classes

Created on 3 Jun 2019  路  3Comments  路  Source: bizz84/SwiftyStoreKit

Platform

  • [x] iOS
  • [ ] macOS
  • [ ] tvOS

In app purchase type

  • [ ] Consumable
  • [ ] Non-consumable
  • [ ] Auto-Renewable Subscription
  • [ ] Non-Renewing Subscription

Environment

  • [x] Sandbox
  • [x] Production

Version

0.13.3

Related issues

Report

Issue summary

We have a wrapper around SwiftyStoreKit, using classes like RetrieveResults, Purchase, PurchaseDetails, RestoreResults. We have a lot of tests for the wrapper to ensure functionality. So far we could instantiate these classes for testing by creating an initialiser in an extension like so:

extension Purchase {
    init(productId: String, transaction: PaymentTransaction) {
        self.productId = productId
        self.transaction = transaction
        self.quantity = 1
        self.needsFinishTransaction = true
        self.originalTransaction = nil
    }
}

With this new compiler directive, this is not possible any more. Instead an error is thrown:

Warning: initializer for struct 'Purchase' must use "self.init(...)" or "self = ..." because it is not in module 'SwiftyStoreKit'

Would it be possible to add public initialisers to these classes? At least for testing?

What did you expect to happen

Being able to create instances of the above classes for testing

What happened instead

Compiler warning that will become an error in Swift 5

enhancement

All 3 comments

Does / would PR #529 fix this issue for you?

Implemented 馃殌! Find the latest changes on the develop branch. Expect to find this in a new release on master within a few days.

@Sam-Spencer Hey, thank you for taking care of this. The change is exactly what we needed and works fine 馃憤

Was this page helpful?
0 / 5 - 0 ratings