Skip to main content

Creating a mock CustomerInfo to use for a Swift UI preview?

  • 7 November 2021
  • 4 replies
  • 478 views

Forum|alt.badge.img+3
  • New Member
  • 1 reply

Hi All,

I’m trying to use Swift UI previews in order to develop my subscription screen, and I want to pass through the `CustomerInfo` object I have stored in my view model to do that (similar to the MagicWeather test app)

But unfortunately, the CustomerInfo() initializer is not accessible outside the module - if I try to create example info, I get the message “'CustomerInfo' initializer is inaccessible due to 'internal' protection level”

This similarly prevents me using a convenience init (since I can’t call the original init) which is what happens in the internal Revenue Cat tests (as far as I can tel)

Has anyone got this working, or does everyone just develop on-device?

Thanks!

Nik

4 replies

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 492 replies
  • November 12, 2021

Hey @nikz!

Since we don’t publicly expose those inits, I don’t think this is currently possible with the SDK. I do think it would be a valuable feature especially when building SwiftUI apps, so I’ll share this with the SDK team and see if we can find a way to get this supported at some point in the future.

I’ll leave the thread open for anyone else to comment in case someone else has any ideas!


Forum|alt.badge.img
  • New Member
  • 1 reply
  • November 26, 2021

I ran into this too but beyond just having some ugly conditional text in my UI itself as placeholders I haven’t had a chance to dig into this much.

my next plan of attack is to reorg my code to be more MVVM so I can find a spot to inject/clean up variables in the view model and reference those in my UI, instead of accessing the RC framework variables directly.


Forum|alt.badge.img+3
  • New Member
  • 3 replies
  • May 6, 2023

Hello, is there any update on this? It would be so helpful to be able to use SwiftUI previews without needing to wrap RC classes.


  • New Member
  • 2 replies
  • July 26, 2024

It seeeems like it’s possible to mock this up using a JSON format decoder since that API is public? We’re going through lots of hoops to figure out how to effectively mock up our SwiftUI previews. :) 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings