swift-package-manager

Get URL to a local file with SPM (Swift Package Manager)

蓝咒 提交于 2020-01-11 06:55:08
问题 I am trying to read .json file in my unit test and running it within Swift Package. Using Xcode 11 and Swift 5.1 let path = Bundle.main.url(forResource: filename, withExtension: "json") // Path is nil I've been told that Swift packages don't have bundles any more. So how can I workaround this? Part of my Swift.package .testTarget( name: "ProjectTests", dependencies: [ .target(name: "Project") ], path: "Tests", exclude: [ "Folder/File.swift" ] ) 回答1: The solution we have found is FileManager .

`swift package generate-xcodeproj` fails with “Swift does not support the SDK”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 21:53:15
问题 I'm having trouble running swift package generate-xcodeproj . I created my package like this: $ /Applications/Xcode9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift package init --type executable (as I have many Xcode versions installed I explicitly targeted a swift binary when running the command so that I don't need to xcode-select all the time) This created a Package.swift with the version header // swift-tools-version:4.0 . Now, when I run swift package

Copying Resource Files For Xcode SPM Tests

吃可爱长大的小学妹 提交于 2019-12-23 04:07:09
问题 I am new to the Swift Package Manager but with its integration into Xcode 11 it is time to give it a try. I have a new application and SPM library within a new workspace. I have a working library with tests and have successfully imported the library into the application. I need to extend the SPM library with new tests that parse json files. I have learned that a resources directory feature is not supported. The only workable scheme seems to be a file copy step added to the library build

Set macOS target for `swift package generate-xcodeproj`?

别来无恙 提交于 2019-12-22 03:52:09
问题 Is there a way to set the macOS target for swift package generate-xcodeproj generates Xcode projects? For example, set default target to "x86_64-apple-macosx10.12". Background Currently, the Xcode 9.2 Swift toolchain shows the following versions on the command line: swift --version # Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) # Target: x86_64-apple-macosx10.9 swift package --version # Apple Swift Package Manager - Swift 4.0.0-dev (swiftpm-13752) The result of swift

How to install Swift package via package manager?

╄→尐↘猪︶ㄣ 提交于 2019-12-21 03:38:21
问题 I am currently following the document from swift.org to play around with the new Swift Package Manager. I cloned the demo project from Github and run the following command from terminal. git clone https://github.com/apple/example-package-dealer.git cd example-package-dealer swift build .build/debug/Dealer While I run swift build , error arise. <unknown>:0: error: no such file or directory: 'build' Any idea? 回答1: I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong

Importing modules with Swift package manager

我是研究僧i 提交于 2019-12-13 03:54:45
问题 I am trying to use Swift's package manager to import external modules in my project. My first module come from the Vapor project. I cannot seem to get it working. I start with swift package init swift package generate-xcodeproj My Package.swift looks like this: import PackageDescription let package = Package( name: "OpenTools", products: [ .library( name: "OpenTools", targets: ["OpenTools"]), ], dependencies: [ .package(url: "https://github.com/vapor/json.git", from: "2.0.0") ], targets: [

What is import func, struct, class, and @_exported in Swift?

非 Y 不嫁゛ 提交于 2019-12-12 07:34:54
问题 In Apple's github for the Swift Package manager they use import func POSIX.isatty import func libc.strerror_r import var libc.EINVAL import var libc.ERANGE import struct PackageModel.Manifest source There is also a file where the only code in it is @_exported source @_exported import func libc.fileno Is this a Swift 3 feature? I can not find anywhere that you can import a type in the Swift documentation and nothing on @_exported . 回答1: You can import only a specific part of a module, not a

swift package manager for library that uses libxml

≯℡__Kan透↙ 提交于 2019-12-12 01:42:36
问题 I'm adding support for the Swift Package Manager to an Obj-C library that depends on libxml . I notice the Package.swift file requires me to specify a package's URL, but what if the package is already on the system? Here's my Package.swift file: import PackageDescription let package = Package( name: "PocketSVG", ) If I run $ swift build I get: fatal error: 'libxml/xmlreader.h' file not found 回答1: In order to use a system library, you need to provide a system module package. For more

Swift Objective-C interoperability on Linux, error: 'Foundation/Foundation.h' file not found

↘锁芯ラ 提交于 2019-12-11 14:09:43
问题 I'm trying to compile a swift program that uses code written in Objective-C on a VM running Linux (Ubuntu 16.0.4, Swift 4.0.3). I get this error when compiling : fatal error: 'Foundation/Foundation.h' file not found #import <Foundation/Foundation.h> ^ 1 error generated. On Mac OS The same program works perfectly on Mac OS. What have I tried ? I've tried reverting to swift 3.1.1 (I remember this working on swift 3 a while ago). I've googled the problem, extensively, and had no success. I've

Swift Package Manager can't find module

纵然是瞬间 提交于 2019-12-11 09:28:38
问题 I'm trying to get familiar with Swift Package Manager. That's what I did: swift package init --type executable added a dependency in Package.swift swift build And everything was fine, but after I tried to import Dependency in the code xcode says: no such module. My Package.swift looks like: import PackageDescription let package = Package( name: "todo-bot", dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"),