Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode and SPM Libraries

I want to code my Project with the Swift Package Manager. The only possible way to get code-completion is through Xcode AFAIK. All other attempts to get code-completion in Vim failed for me.

Setup of my Swift package:

$ mkdir SwiftProject
$ cd SwiftProject

$ swift package init --type executable

This step generates the standard package structure with Package.swift, Source folder containing main.swift and so on.

$ swift package generate-xcodeproj

The last step generates SwiftProject.xcodeproj with all settings for building the swift package from Xcode.

Everything works so far, until dependencies are added through Package.swift.

My current Package.swift:

import PackageDescription

let package = Package(
    name: "SwiftProject",
    dependencies: [
        .Package(url: "https://github.com/czechboy0/Socks.git", majorVersion: 0, minor: 7)
    ]
)

Now when I import SocksCore in my main.swift and work with it, compiling it through CLI swift build works fine and it runs. But my Xcode-Project doesn't compile, because it can't find the SocksCore module. I think I need to import the .dylib-Files, so Xcode can build the project.

To my Problem now: How do I generate those dynamic libraries with the SPM? I don't find a way to do this. Every tutorial about using SPM with Xcode has got this .dylib or static libraries .a, but this tutorials are build with an older development snapshot version than mine. I build with DEVELOPMENT-SNAPSHOT-2016-06-06-a. I can't find a way to build them with my snapshot. Is this not possible anymore? Or what am I doing wrong at this point?

Or is there another way working with SPM and Xcode? Would be nice if I could find a solution to start my project.

like image 867
Dennis Hübner Avatar asked Jun 30 '16 08:06

Dennis Hübner


2 Answers

You currently need to regenerate the Xcode project manually whenever you make a change to the structure of the package. That includes adding new dependencies, but also any time you add a new source file.

like image 135
Daniel Dunbar Avatar answered Sep 23 '22 19:09

Daniel Dunbar


Just to clarify/simplify Daniel's Dunbar answer, after every

swift package update 

u should generate xcodeproj again:

swift package generate-xcodeproj
like image 32
Zaporozhchenko Oleksandr Avatar answered Sep 21 '22 19:09

Zaporozhchenko Oleksandr