Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swift Package Manager (SPM) for Existing [iPhone App] XCode Project (Having Swift + Objective C Files)

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?

like image 914
Niraj Avatar asked Feb 03 '17 09:02

Niraj


People also ask

Can I use Swift package manager with Objective-C?

When you read the term “Package Manifest”, it is referring to your Package. swift file. As of today 10/10/19, you cannot have mixed Swift and Objective-C files in the same package's source code. (They may exist in the same 'Source' directory since you can explicitly exclude files from being compiled)

How do I add a Swift package to an existing project?

Open your Xcode project, navigate the File tab within the macOS bar, and click on “Add Packages”. In the Add New Package window, you can select from recently used or Apple Swift Packages. Alternatively, you can search for a package via the name or the URL to the Github page.

Does Swift package manager support iOS?

The Swift Package Manager can be used to add external libraries in Xcode projects. This makes the tool a good alternative to Cocoapods and Carthage for managing the dependencies of an iOS project.


2 Answers

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

like image 134
Josh Channings Avatar answered Oct 06 '22 01:10

Josh Channings


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.

like image 21
T. Swifty Avatar answered Oct 05 '22 23:10

T. Swifty