Implement AnyView.init(_fromValue:)#20
Open
nerdsupremacist wants to merge 9 commits intoCosmo:masterfrom
Open
Conversation
…using C’s extern function
Author
Author
|
@Cosmo I took the contents of this PR and managed to make it a bit more generic: https://github.com/nerdsupremacist/AssociatedTypeRequirementsKit. I can switch it to that implementation if you feel like it, but I understand if you want to keep the number of dependencies of this as low as possible |
Owner
|
@nerdsupremacist I finally took some time to take a look at the amazing work you did. To be honest, I won't mind having this as a dependency. |
Author
|
Cool! I've changed the PR to only use the library instead ;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements
AnyView.init(_fromValue:).I need this functionality for my library.
Since I didn't know how to implement it, I first checked how you do it here, and noticed that you didn't. But it was marked as TODO.
I guess you probably found to be a real pain in the a**.
I hope you don't hate my implementation. It uses some runtime functions, symbol lookups and exploits how protocol conformance looks during runtime.
It's not exactly the simplest implementation. But I couldn't figure out a simpler way to do it.
I had to add a C target to be able to include
_GNU_SOURCEunder linux, becausedlopenis not defined for Swift in Linux. Refer to this forum post for more info.I have not tested this on linux, but it should work.
I added two tests which you can run to check it.