Search code examples
iosswiftmacosswift-package-manager

Basic Swift Package Manager Questions About Multiplatform Libraries


I'm having a devil of a time figuring this out. I know how to do this with CocoaPods, but SPM seems to be getting the better of me. I haven't been able to figure anything out from the official SPM docs, regarding this specific issue.

I am developing a Swift Framework, designed to be embedded in apps and applications (iOS and OSX). I have a couple of targets in the xcodeproj, with targets for each platform. I can run xcodebuild, and do it individually, or use CocoaPods to generate them on demand.

I can't seem to get SPM to do the same thing. It stubbornly only builds the OSX version, and I can't see any commands to retarget the same source files.

It's really important to use the same source files, as opposed to having two copies of the same files, so all my targets will need to point to the same directories.

Here's what the Package.swift file looks like now:

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "WhiteDragon",
    products: [
        .library(
            name: "WhiteDragon",
            targets: ["WhiteDragon"]
        ),
    ],
    targets: [
        .target(
            name: "WhiteDragon",
            dependencies: [],
            path: "WhiteDragon/Classes"
        ),
        .testTarget(
            name: "WhiteDragonTests",
            dependencies: ["WhiteDragon"],
            path: "WhiteDragonTests"
        ),
    ],
    swiftLanguageVersions: [.v4_2]
)

I'm continuing to dig, and trying out all kinds of wild ideas, but I don't have it yet. I'm fairly new to SPM, and I'm finding that pretty much everyone is either only discussing using it to pull dependencies, or they use the same, primitive little structure that you get with init.

I would love to RTFM, but I've been a bit disappointed, so far, and would appreciate being directed towards an "M" that could give me the answer.

Thanks so much!

UPDATE: Here's the podspec, that gives me what I need (With some Sir Terry redactions):

Pod::Spec.new do |spec|
    spec.name                       = 'WhiteDragon'
    spec.summary                    = 'A Cocoa Framework that Provides an Application-Level Interaction With a BAOBAB Server.'
    spec.description                = 'The White Dragon Cocoa Framework is a Swift shared framework designed to allow easy development of iOS/MacOS RVP apps. It completely abstracts the connection to BAOBAB Servers, including administration functions.'
    spec.version                    = '1.0.0.1000'
    spec.ios.deployment_target      = '11.0'
    spec.osx.deployment_target      = '10.11'
    spec.homepage                   = '<MILLENIUM HAND AND SHRIMP>'
    spec.social_media_url           = 'https://twitter.com/BUGRIT'
    spec.author                     = { '<MUMBLE, MUMBLE>' }
    spec.documentation_url          = '<BUGRIT>'
    spec.license                    = { :type => 'MIT', :file => 'LICENSE.txt' }
    spec.source                     = { :git => '<GASPODE!>', :tag => spec.version.to_s }
    spec.source_files               = 'WhiteDragon/Classes/**/*'
end

Solution

  • Currently SPM does not support iOS targets.

    At this time there is no explicit support for depending on UIKit, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

    Depending on Apple Modules