Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @available(iOS 16, *) to generated class #67

Closed
nathansalaun-sofia opened this issue Jul 25, 2024 · 7 comments · Fixed by #68
Closed

Add @available(iOS 16, *) to generated class #67

nathansalaun-sofia opened this issue Jul 25, 2024 · 7 comments · Fixed by #68

Comments

@nathansalaun-sofia
Copy link

When using @Mockable on my project I have the following error: Runtime support for parameterized protocol types is only available in iOS 16.0.0 or newer. My app targets iOS 15.

It's not a problem in test targets because I only run tests on the latest iOS version. However in order to compile, the mock needs @available(iOS 16, *).

@Kolos65
Copy link
Owner

Kolos65 commented Jul 25, 2024

Can you show the protocol you encountered this with?

@nathansalaun-sofia
Copy link
Author

I can't show you the whole protocol for privacy reasons but I think it comes from the following properties:

  var foo: any SomeProtocol<SomeStruct> { get }
  var bar: any SomeProtocol<AnotherStruct> { get }
  
  var baz: any AnotherProtocol<SomeStruct> { get }

I guess the runtime support for any isn't full until iOS 16 for some cases, and the generated mock falls into those cases.

@Kolos65
Copy link
Owner

Kolos65 commented Jul 25, 2024

Adding the @available(iOS 16, *) attribute to every mock implementation would just burry this issue. It would still make parameterized protocols unusable from < iOS 16 projects. I think regardless of your test target, your app target will be compiled with the iOS 15 SDK and this would not fix it.

You are using primary associated type protocols in your iOS 15 project which cannot be used when casting. Casting type erased mock values is a core part of the library so as I see it this Swift feature is not compatible with mockable in your case on iOS 15.

@nathansalaun-sofia
Copy link
Author

The compiler asks me to add the @available attribute on the generated class though so surely it must work?

What's missing from iOS 15 is runtime support, which doesn't have anything to do with the SDK used to compile the app.

iOS 15 has partial runtime support for primary associated types and inside the app, we do not (because we can't) use patterns that require iOS 16 runtime support. But the rest of the app works fine, we just can't use primary associated types in function parameters (I believe), which is what the mock does.

The right thing to do would be to have the macro detect protocols with primary associated types and add the annotation on the class if there are any, since the generated code requires the iOS 16 runtime in that case.

@Kolos65
Copy link
Owner

Kolos65 commented Jul 25, 2024

I see, you are right... Will try to write the code for detecting this edge case. Will request a review from you when its ready.

@Kolos65
Copy link
Owner

Kolos65 commented Jul 30, 2024

@nathansalaun-sofia Pls check out my PR if you can at: #68

@Kolos65
Copy link
Owner

Kolos65 commented Aug 2, 2024

@nathansalaun-sofia The fix is available in 0.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants