7
votes

I am trying to create Library which I can use into my Existing XCode Project (iOS App). I am aware that Swift Package Manager now support generating Xcode project with command

swift package generate-xcodeproj

But I am not creating new project. In my existing project having Objective C & Swift Files, How can I use newly created Swift Package?

How to add Package.swift file to my current Project?

3

3 Answers

4
votes

As far as I know you can't use SPM right now within iOS apps.

You can use it in hosted environments for example if you are hosting a web application with Vapor on a Mac or on Linux.

6
votes

To use Swift (v4) Package Manager with iOS you have to jump through a couple of hoops.

Basically,

  1. Make a Package.swift for your app's dependencies
  2. Use the output of swift package generate-xcodeproj, modified to work with iOS, as a subproject of your main App xcodeproj
  3. Link your dependency Frameworks as you normally would

I have an example with reproduction steps

2
votes

Both other answers (Josh, T. Swifty) are outdated. You don't need to generate an xcodeproj based off a Package.swift, in fact, swift package generate-xcodeproj is a deprecated command.

If you're making an app, just add your Swift Package in Xcode (in the project > Swift Packages tab). Only create a Swift.package if you're making an executable or library, instead of an application for iOS, macOS, etc.

The guide is: Adding Package Dependencies to Your App