pointfreeco / episode-code-samples

💾 Point-Free episode code.
https://www.pointfree.co
MIT License
939 stars 289 forks source link

[0171-modularization-pt1] Setting Up #108

Closed bradhowes closed 2 years ago

bradhowes commented 2 years ago

I came back to this exciting episode to review how to actually perform the magic of getting an existing project involved with Swift packages. However, I'm a bit confused about the "existing" part. From what I saw, you had an existing project "SwiftUINavigation" that resided in a new directory called "Inventory", and it is in that directory that you ran swift package init. I too did this and it worked, but I'm left with the package files outside of git management from my existing project. How did you reconcile that? Is there some magic here I am missing (git or otherwise)?

I tried moving my project into a new directory and then doing the steps, but I failed to change the parent directory name (so I had Foo/Foo) which at first appeared to work, but I think there is some funky name collision stuff happening now that is causing me all sorts of grief that I did not have on my first attempt. My third attempt will be to again do the move, but this time making sure to change the name of the parent directory.

Curious about your thoughts on how this is working and should work. How safe do you think this kind of setup will be in the future? (Additional magic is the Package.swift file used to hide the duplicated original project tree).

bradhowes commented 2 years ago

More thoughts: I wanted to change the legacy name of my original package name and saw that Xcode just has it as essentially a soft link to '..'. This gave me the idea to try something else instead of what your video started out with:

Voila! The Packages folder appears as a Swift packages folder and all is good. No need for a mystery Package.swift file, and there is no moving around of stuff to stay in the Git realm.

mbrandonw commented 2 years ago

Hi @bradhowes, sorry for not responding earlier, but glad you got it figured out.

It does seem that the project we started with for the episode was in a slightly "not default" state, and we didn't notice because we weren't using git version control for that directory. So that meant we had a root directory with a sub-directory, and that sub-directory held our application. Then it was easy to just initialize an SPM module at the root.

The solution you came up with works (putting the SPM package in a sub-directory), and alternatively you could have moved your entire application into a sub-directory, but as you noted there may be a few things to fix along the way, which is a bummer. We slightly prefer the latter because it makes the SPM packages closer to the root, and we spend 99% of our time editing that code rather than the application code.

But glad it's working for you now!

bradhowes commented 2 years ago

Thanks for the response. Just to be clear, there is no difference between the two approaches at the end when you are in Xcode. You still need to open the project, and not the Packages.swift file so the end result is the same AFAICT. But it is purely academic at this point. All good.