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

Macro type check for protocol failed #15

Open
miku1958 opened this issue Feb 16, 2023 · 0 comments
Open

Macro type check for protocol failed #15

miku1958 opened this issue Feb 16, 2023 · 0 comments

Comments

@miku1958
Copy link

miku1958 commented Feb 16, 2023

Hi, I tried to add a macro to convert ObjC's Class (AnyClass in Swift) to the actual type.
miku1958@e9027e4

I've added two functions here that are implemented in ObjC, and I've added them as swift versions in the example
classConforming is to retrieve the class that conform the ObjcProtocol from a dictionary, it return AnyClass
objectConforming is to retrieve the object that conform the ObjcProtocol from a dictionary, it return Any

I can't write a Swift version directly due to compiler limitations, so I'd like to borrow the Macro implementation

The problem happened when I used classConforming and convert the ObjcProtocol to:
classConforming(to: ObjcProtocol.self) as? ObjcProtocol.Type

Compiler give me this error:
Cannot convert value of type '(any ObjcProtocol.Type)?' to type '(any ObjcProtocol).Type?' in coercion

I tried to return another Generic Type or return Any directly but fail, any way I can fix it?

Thanks!

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

No branches or pull requests

1 participant