NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Instructions for making a library?

Forums > macOS

Over my career I've often wound up taking code from an old project and packaging it up as a library to be included in whatever I'm working on at the moment. I know how to do that with Java, but now that I'm learning Swift and SwiftUI I'd like to know how to do it with Swift. I've spent a couple hours looking for tutorials on this, but so far everything has been specifically about making iOS libraries, while the project I'm working on now is specifically for macOS.

Where should I look to find out how I'm supposed to be doing this? Any ideas?


Hi Do you mean that you want to insert code into your project or your want to SPM (Swift Packages) that you can import

If you want to insert code that you have written into a project often (ie. I have one for Bundle-Decodable that decode JSON in Bundle)

  1. First highligh the code
  2. then goto Editor in menu bar
  3. Create Code Snippet

Then when you use it click on + in top right and select it.

If you want a Swift Package. I am not sure but you might want to see Stewart Lynch from CreaTech. He is on this forum and has a YouTube channel


Thanks for the pointer. I actually don't mean either of those scenarios, but that should help me move forward. What I really mean is, "Hey, these utility classes that I've built for project A would be useful now in project C. Oh, and now I'm working on project D and it would be handy to have those things...gosh, I wish I could just package up all that Swift code that I keep copying around and instead put it into a CocoaPod or something so that I can just have one place where I need to fix that sneaky bug instead of having to remember to do it everywhere."


Hacking with Swift is sponsored by MadMachine

SPONSORED Want to explore your Swift skill outside of the Apple world? Join the MadMachine community and start to program microcontrollers in Swift.

Get it now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.