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

Support hot reloading with Inject #1710

Merged
merged 4 commits into from
Jan 8, 2025
Merged

Conversation

mplorentz
Copy link
Member

@mplorentz mplorentz commented Dec 27, 2024

Description

This adds a framework for hot reloading to Nos. I tried it out in my hackathon project and thought it might be useful as a faster, more reliable alternative to SwiftUI previews.

How to test

  1. Follow the new instructions to set up hot reloading in the CONTRIBUTING.md.
  2. Run the Nos scheme in the simulator.
  3. (Optional) open the console log and filter it by "💉" to see the Inject logs. If you set it up correctly you should see something like:
💉 InjectionIII connected /Users/matt/v/nos/Nos.xcodeproj
💉 Watching files under the directory /Users/matt/v/nos`

If not, maybe you need to watch the correct directory from the InjectionIII menubar app.

  1. Open HomeFeedView
  2. Change the background color to something bright like red
  3. Hit command-s to save. You should see Inject recompile the file in the logs
  4. For some reason our views don't update right away, but if you tap another tab and then tap the home tab again the background color should change.

Screenshots/Video

(ignore the fact that in the video the simulator is showing my hackathon branch)

Screen.Recording.2024-12-27.at.10.00.28.AM.mov

@mplorentz mplorentz marked this pull request as draft December 27, 2024 15:08
@mplorentz
Copy link
Member Author

shoot this is on the wrong branch. I will have to fix it later.

@mplorentz mplorentz force-pushed the hot-reloading-with-inject branch from 0c57bd1 to 0dd8f24 Compare December 27, 2024 18:43
@@ -53,6 +53,10 @@ For now `main` is the main branch and code improvements are made in topic branch

A maintainer will review your code and merge it when it has the required number of approvals.

## Hot Reloading

We make use of the [Inject](https://github.com/krzysztofzablocki/Inject) framework for hot reloading debug builds. To set up hot reloading, follow the [documentation](https://github.com/krzysztofzablocki/Inject?tab=readme-ov-file#individual-developer-setup-once-per-machine).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this documentation is too light, but I am kinda rushing to throw this PR out there. Maybe the reviewer can tell me if it's enough or document the steps they had to take.

For instance, the first thing their documentation says to do is add some linker flags which is already done. So at least that part is superfluous. It's been a while since I set this up so I don't remember what I did exactly.

@mplorentz mplorentz marked this pull request as ready for review December 27, 2024 18:53
@pelumy
Copy link
Contributor

pelumy commented Jan 2, 2025

👀

@pelumy
Copy link
Contributor

pelumy commented Jan 2, 2025

I need to download Xcode from the App Store to continue testing this. I currently have the one from the "Xcodes app". I will pause testing this to download Xcode from the App Store over the weekend. I can do that now if it is very much important. But I will need to delete my current Xcode tho download that because of space issues and that can delay me doing other things.

@pelumy
Copy link
Contributor

pelumy commented Jan 6, 2025

I continued to test this today, I didn't need to do anything extra-ordinary in the documentation linked. I only had to install inject and then run the project from Xcode. I searched the logs and found what Matt asked us to search, only issue I was getting was:
💉 💉 ⚠️ Your project file seems to be in the Desktop or Documents folder and may prevent InjectionIII working as it has special permissions.

I did some googling and saw that people were experiencing it too and it was due to permission issues. I tried to give Injection permission to read my files, but that was impossible. I saw online that it would work if I moved the nos folder directly to desktop. I tried to move the folder but I was getting some errors. I will have to reclone again to see if that would work.

@pelumy
Copy link
Contributor

pelumy commented Jan 7, 2025

It worked after I moved the nos folder to my desktop and it wasn't nested in another folder. I was able to see the background color of the home view change after selecting another tab and going back to the home tab.

@pelumy
Copy link
Contributor

pelumy commented Jan 7, 2025

This works for me. Thanks for working on this @mplorentz

Copy link
Contributor

@pelumy pelumy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💉

@mplorentz mplorentz enabled auto-merge January 8, 2025 22:19
@mplorentz mplorentz added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit b8eca9d Jan 8, 2025
4 checks passed
@mplorentz mplorentz deleted the hot-reloading-with-inject branch January 8, 2025 22:35
@mplorentz
Copy link
Member Author

mplorentz commented Jan 14, 2025

@pelumy

I need to download Xcode from the App Store to continue testing this. I currently have the one from the "Xcodes app". I will pause testing this to download Xcode from the App Store over the weekend. I can do that now if it is very much important. But I will need to delete my current Xcode tho download that because of space issues and that can delay me doing other things.

I actually fixed this by creating a symbolic link from /Applications/Xcode 16.0.app -> /Applications/Xcode.app like this: sudo ln -s "/Applications/Xcode 16.0.app" "/Applications/Xcode.app".

But you can also install the App Store version of Xcode alongside the one from Xcodes.app. And you can have multiple versions from Xcodes.app isntalled at the same time too. They all work side by side, I just try not to have them launched at the same time.

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 this pull request may close these issues.

2 participants