NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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

1      

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 Emerge

SPONSORED Emerge helps iOS devs write better, smaller apps by profiling binary size on each pull request and surfacing insights and suggestions. Companies using Emerge have reduced the size of their apps by up to 50% in just the first day. Built by a team with years of experience reducing app size at Airbnb.

Set up a demo!

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

Reply to this topic…

You need to create an account or log in to reply.

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.