roc icon indicating copy to clipboard operation
roc copied to clipboard

Update Swift example

Open TeamPuzel opened this issue 1 year ago • 3 comments

Hi! I was browsing the examples and noticed that Swift needed some love. The language improved a lot for low level use cases since this example was written and I thought I'd make it more up to date 🙂

  • Converted the example to pure Swift
    • removed the C header thanks to extern support
    • Removed Foundation. It is not portable and unavailable in embedded mode. Creating Swift strings now writes String memory directly, instead of using a complicated objc-bridged data structure.
    • Used naming conventions idiomatic to the language (count vs length etc)
    • Removed free functions in favor of methods and computed properties
  • Used the new embedded mode to make binaries portable, tiny, faster and easier to link with
  • Used native Swift allocation APIs instead of using libc directly, which is more portable and doesn't require importing anything.
  • Removed return keywords in single expression functions
  • Used native pointer types instead of integers

Is there somewhere else I have to modify to build using the new flags?

Where can I find any resources/documentation I'd need if I wanted to implement a library for seamless Swift/Roc integration? I saw that Rust and Zig have some "glue" code but Swift does not appear to, it would be fun to write if that's useful 🙂

TeamPuzel avatar Jun 19 '24 16:06 TeamPuzel

Oh cool. I need to check this out.

I started a template repository to help people get started, but my swift knowledge is lacking.

https://github.com/lukewilliamboswell/roc-platform-template-swift

lukewilliamboswell avatar Jun 19 '24 20:06 lukewilliamboswell

If you're interested in Swift glue, I'd love to help you get started. DM me on zulip maybe would be best.

I started this repository to try and organise glue better.

https://github.com/lukewilliamboswell/roc-glue-code-gen

lukewilliamboswell avatar Jun 19 '24 20:06 lukewilliamboswell

If you're interested in Swift glue, I'd love to help you get started. DM me on zulip maybe would be best.

Sure, I'll do that tomorrow 👍🏻

TeamPuzel avatar Jun 19 '24 21:06 TeamPuzel

Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked Closed are not deleted, so no matter what, the PR will still be right here in the repo. You can always access it and reopen it anytime you like!

github-actions[bot] avatar Jul 21 '24 01:07 github-actions[bot]