Swift Package Manager - UIKit Dependency

孤者浪人 提交于 2019-12-03 15:24:17

问题


I have a Package.swift in my project like:

import PackageDescription

let package = Package(
    name: "ProjectName",
        dependencies: [
           .Package(url: "https://github.com/intellum/neeman.git", majorVersion: 0)
        ]
 )

When I run swift build I get errors like…

/project/Packages/WebViewController.swift:1:8: error: no such module 'UIKit'
import UIKit
       ^

Where should I tell the swift package manager where to find UIKit?


回答1:


The Swift Package Manager builds executables to run on OS X (or Linux); UIKit is a framework in iOS and won't be accessible.

It may be iOS, tvOS and others become accessible as Swift Package Manager evolves.

On Dec 4, 2015, at 5:39 PM, Daniel Dunbar (@apple.com) wrote:

...

Right, now we only compile for the host platform (OS X or Linux, currently). Among other things, we currently have no knowledge (or options to choose) what SDK or architecture you are targeting. We also have no mechanisms for specifying what platforms targets are compatible with in the manifest.




回答2:


Currently Swift Package Manager has full Xcode support. I was able to get around this error by specifying in my Package.swift manifest that the platform was iOS.

let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v8)
    ],

Then you can open the Package.swift file in Xcode and it will just work.




回答3:


You have to change some swiftc options to build the project against proper sdk and target

swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"


来源:https://stackoverflow.com/questions/34778823/swift-package-manager-uikit-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!