Swift Packages

RSS for tag

Create reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers using Swift Packages.

Swift Packages Documentation

Posts under Swift Packages tag

199 Posts
Sort by:
Post marked as solved
6 Replies
2.2k Views
Hi, I've got a Swift Framework with a bunch of Metal files. Currently users have to manually include a Metal Lib in their bundle provided separately, to use the Swift Package. First question; Is there a way to make a Metal Lib target in a Swift Package, and just include the .metal files? (without a binary asset) Second question; If not, Swift 5.3 has resource support, how would you recommend to bundle a Metal Lib in a Swift Package?
Posted
by
Post marked as solved
3 Replies
1.6k Views
Trying to build a project in Xcode that has some SPM packages that are private under my personal GitHub. Originally my GitHub account was not configured with Xcode 12, but after adding the account and multiple "Clean Build" and "Reset Package Caches". Xcode is still is not able to resolve the packages.
Posted
by
Post not yet marked as solved
2 Replies
1.4k Views
I have created a swift package and successfully added some stub code, imported into another class import PackageName This all works as expected when building in debug configuration. When I try to build for release using xcodebuild, it fails with "no such module : PackageName" Is there something missing that dictates how a package works in different configurations? Thanks
Posted
by
Post not yet marked as solved
8 Replies
2.9k Views
Our project is split up into multiple Pods with CocoaPods and I'm currently trying to convert all of our podspecs to SPM. One of our projects has XCFramework dependencies that I'm trying to include from a local source, but my project files are complaining that the modules couldn't be found when I try to import them. Is there something I'm missing here? My Package.swift file looks something like this: // swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "MyPackage",     defaultLocalization: "en_us",     platforms: [         .iOS(.v12),         .watchOS(.v6),         .macOS(.v10_15)     ],     products: [         .library(             name: "MyPackage",             targets: [                 "MyPackage"             ]),     ],     dependencies: [     ],     targets: [         .target(             name: "MyPackage",             dependencies: [                 .byName(name: "LocalXCFramework")             ],             path: "Sources/"         ),                  .binaryTarget(             name: "LocalXCFramework",             path: "Frameworks/LocalXCFramework.xcframework"         )              ] ) In this example, if I try to import the modules from LocalXCFramework, I get an error saying it couldn't be found.
Posted
by
Post not yet marked as solved
16 Replies
4.7k Views
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package. How can I access Xcode Previews from a package that depends on other packages?
Posted
by
Post not yet marked as solved
4 Replies
1.6k Views
In the WWDC session Explore Packages and Projects with Xcode Playgrounds. The demo showed a playground NutritionFacts inside of a package. I tried to create a playground inside my package and the playground cannot find my module. What setup needs to occur to allow the playground to be able to use the module besides typing import module
Posted
by
Post not yet marked as solved
6 Replies
3.4k Views
I have been able to ship some image and asset catalogs in a Swift package with success using Xcode 12b1 and Swift 5.3. I am not having so much luck with using a custom .ttf file in a Swift Package. I am loading a .ttf file in the manifest like so: .target( 	name: "BestPackage", 	dependencies: [], 	resources: [ 		.copy("Resources/Fonts/CustomFont.ttf"), 		.process("Resources/Colors.xcassets") 	] ), And I noticed that there's no initializer on the Font type in SwiftUI to include an asset from a module. For example, this works: static var PrimaryButtonBackgroundColor: SwiftUI.Color { 	Color("Components/Button/Background", bundle: .module) } However, there's no way to specify where a font is coming from. I was hoping that loading it into the module would emit it into the target for use, but no such luck: static var PrimaryButtonFont: Font {   Font.custom("CustomFont", size: 34) } This does not load the font as expected. I'm investigating using a CoreText api to try and trick it into loading, but I feel like there should be an easier way. Any advice?
Posted
by
Post marked as solved
16 Replies
11k Views
I have compiled Google's WebRTC library and bundled up everything into xcframework in order to distribute as a binary framework in Swift package manager. When I add the package to my project it compiles and runs on a simulator. However, on a physical device, it crashes on launch with the following error: dyld: Library not loaded: @rpath/WebRTC.framework/WebRTC Referenced from: /private/var/containers/Bundle/Application/AA9F8C9C-7EF4-4556-8848-1EEFE1785658/WebRTC-Demo.app/WebRTC-Demo Reason: image not found dyld: launch, loading dependent libraries DYLDLIBRARYPATH=/usr/lib/system/introspection DYLDINSERTLIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib Further investigation: After archiving the project and exporting ipa file, the ipa file is missing the binary framework and still crashing on launch. Removing the Swift package and attaching the xcframework manually (by drag and drop) works on Simulators and physical devices. Tech specs XCFramework created on macOS 10.15.5 with Xcode 11.5 Used Xcode 12.0 beta 1 on macOS 10.15 for the app which uses the framework. I got the error above on iPhone X and iPad pro 10.5" Used the following Package.swift - https://github.com/stasel/WebRTC-iOS/blob/xcode-12/Package.swift file. Framework download link can be found in the Package.Swift file above. Any suggestions/insights would be helpful. Thanks!
Posted
by
Post marked as Apple Recommended
3.7k Views
Hello! We have some resources included as part of our test target like so:         .testTarget(             name: "MyProjectTests",             dependencies: ["MyProject"],             resources: 							[.process("Assets/Test_5s.mov")]) However, when running the following command: swift package generate-xcodeproj the generated package does not include the assets. Additionally the code to access the resources won't compile because there is no auto-generated file to provide the 'module' extension for 'Bundle'. Bundle.module.url(forResource: "Test_5s", withExtension: "mov") results in a "Type 'Bundle' has no member 'module'" compilation error. Is this a known issue, or am I approaching this incorrectly if I want to have a project for the package? Currently using Xcode 12 beta 2
Posted
by
Post not yet marked as solved
11 Replies
6.8k Views
Xcode 12 beta 3 introduces the new -debug-symbols option for xcodebuild -create-xcframework. After testing, I was unable to use that option correctly. I setup a framework target with a single struct in it for testing purposes. I create an xcarchive of the framework this way: $ xcodebuild -scheme "BrazeKit" -configuration "Release" -sdk "iphones" -archivePath ./.build/xcarchives/BrazeKit/iOS/iphoneos archive This generates the expected ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive which contains: . ├── BCSymbolMaps │   ├── 0A25AE50-A721-30A0-BC09-E8CFA503D4A6.bcsymbolmap │   ├── 13B3D8E5-9D37-300A-8EB9-72A33AD89E26.bcsymbolmap │   ├── 7D10C250-E408-334E-92FC-3444B7D0E067.bcsymbolmap │   └── AF8424FB-543E-37E1-A7BF-64DE4BCABD39.bcsymbolmap ├── dSYMs │	 └── BrazeKit.framework.dSYM │			 └── Contents │					 ├── Info.plist │					 └── Resources │							 └── DWARF │									 └── BrazeKit └── rest omitted for the sake of brevity I can build an XCFramework from that archive with: $ xcodebuild -create-xcframework -framework ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/Products/Library/Frameworks/BrazeKit.framework -output BrazeKit.xcframework But I am unable to attach any debug symbols using -debug-symbols: $ xcodebuild -create-xcframework -framework ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/Products/Library/Frameworks/BrazeKit.framework -debug-symbols ./build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/dSYMs/BrazeKit.framework.dSYM	-output BrazeKit.xcframework error: the path does not point to a valid debug symbols file: ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/dSYMs/BrazeKit.framework.dSYM Using the dSYM package BrazeKit.framework.dSYM $ xcodebuild -create-xcframework -framework ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/Products/Library/Frameworks/BrazeKit.framework -debug-symbols ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/dSYMs/BrazeKit.framework.dSYM/Contents/Resources/DWARF/BrazeKit -output BrazeKit.xcframework error: the path does not point to a valid debug symbols file: ./.build/xcarchives/BrazeKit/iOS/iphoneos.xcarchive/dSYMs/BrazeKit.framework.dSYM/Contents/Resources/DWARF/BrazeKit Using the file under the DWARF directory in the dSYM package Whichever dSYM file I pass, I always get the error the path does not point to a valid debug symbols file. Could you provide an example on how to correctly use the option -debug-symbols? Thanks,
Posted
by
Post not yet marked as solved
4 Replies
54k Views
Hi, I'm getting warning in my Swift package where one of external dependency supports from iOS8.0, is it as bug in xcode or do we need to ask 3rd party developer to remove iOS8.0 supports, i believe they need to support library in cocoapods for iOS8.0 as well Warning: IPHONEOSDEPLOYMENTTARGET is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99 Forum thread: https://forums.swift.org/t/unable-to-import-multiple-targets-from-external-dependency/39030/3
Posted
by
Post marked as solved
1 Replies
989 Views
In Xcode 12, I'm trying to add a package dependency to an Xcode project. Specifically, this is the swift-bson package from mongoDB - https://github.com/mongodb/swift-bson. When adding the dependency to the project using File -> Swift Packages -> Add Package Dependency, I can find the git repository just fine. But when I try to add it, I get an error with the following messages: [Complete] Fetching https://github.com/mongodb/swift-bson.git 0.6 seconds [Error] target 'bson' referenced in product 'bson' could not be found I'm new to packages so I might be misunderstanding how this feature is supposed to work, but I'm pretty sure this is what the docs say I should do. This might also be an Xcode 12 thing, I know they changed a couple of things related to packages. Tried: Creating my own package and adding this one as a dependency Switching project targets Adding to a specific target instead of the whole project Getting a different version of the package Can someone help shed some light on what might be wrong?
Posted
by
Post not yet marked as solved
1 Replies
634 Views
Hey everyone, I have been working on a Metal Renderer and I would like to set this up as a Swift Package. However I am running into some issues with setting up the package and I have not been able to find a solution, so I thought I'd give it a shot here. To keep it simple, in my project I have a .swift file doing the rendering, a .metal file that contains my shader code and a .h file (which is a bridging header in my project) which contains stuff like Types to be shared between the metal shaders and the swift code. I am stuck of how I can include the .h and .metal files in the swift package. Right now the swift file doesn't pick up on the stuff inside the header file and the metal file is just loaded with errors as if it doesn't recognize the file type. Ideally I would also like to expose this header to the outside. Has anyone ever done something like this, or know if this is even possible? Thanks in advance, and kind regards
Posted
by
Post not yet marked as solved
1 Replies
1.1k Views
I've been trying to convert a set of app and library projects to use swift packages for dependencies (previously used Carthage), and I've run into an issue where Xcode is throwing me a diagnostic for "Unexpected duplicate tasks". The setup: A dynamic library package which includes some file resources (not any special resources like asset catalogs or CoreData models). Let's call this LibA. A second dynamic library, containing test utilities, which depends on LibA. Let's call this one LibB. An iOS app project, where the app target depends on LibA, and the unit test target depends on LibB, and transitively through LibB, depends on LibA. The result is Xcode will compile the app target, but when compiling the unit test target, fails with the diagnostic: Unexpected duplicate tasks: 1) Target 'TestPMAppTests' (project 'TestPMApp') has copy command from '/Users/someone/Library/Developer/Xcode/DerivedData/TestPMApp-bsobwbvrasoqbtejzhodakcdkqqu/Build/Products/Debug-iphonesimulator/liba_liba.bundle' to '/Users/someone/Library/Developer/Xcode/DerivedData/TestPMApp-bsobwbvrasoqbtejzhodakcdkqqu/Build/Products/Debug-iphonesimulator/TestPMApp.app/PlugIns/TestPMAppTests.xctest/liba_liba.bundle' 2) Target 'TestPMAppTests' (project 'TestPMApp') has copy command from '/Users/someone/Library/Developer/Xcode/DerivedData/TestPMApp-bsobwbvrasoqbtejzhodakcdkqqu/Build/Products/Debug-iphonesimulator/liba_liba.bundle' to '/Users/someone/Library/Developer/Xcode/DerivedData/TestPMApp-bsobwbvrasoqbtejzhodakcdkqqu/Build/Products/Debug-iphonesimulator/TestPMApp.app/PlugIns/TestPMAppTests.xctest/liba_liba.bundle' Is this something that is expected behaviour here?
Posted
by
Post not yet marked as solved
18 Replies
6.2k Views
Hello, We have a situation where: we have a library A distributed as an xcframework. this library A is used in a swift package B that includes it as a binary target. our final iOS App uses our swift package B with swift package manager. We first had issues with code signing and solved it by adding a build phase that code sign the framework A when building the App. Now everything is fine when running in debug but when trying to archive the App, We have a compilation error saying Xcode doesn’t find the framework A.. we try a lots of different setup but didn’t find any solution to fix this compilation error. Any idea on how we could solve this issue? Thanks!
Posted
by
Post not yet marked as solved
3 Replies
2.7k Views
Hey people, I'm using (or rather trying to use) Swift Packages for my project. This is not about the countless other bumps I found along the road. (Xcode/SPM is still very beta with Xcode 12.0.1 but I'll reserve complaining about for another day). But one I did not even something vaguely useful when googling it. So I started out using file paths for my dependencies, like: .package(name: "BlaBla", path: "/Users/me/GitDev/BlaBla") for some reason that does not work when you want to chain dependencies (Another bug to fix, Apple!). So I wanted to change to versions using a git repo. I gave my repo a tag and put in: .package(url: "ssh://me@server.local/usr/home/me/GitDev/BlaBla", from: "0.0.1"), On the command line SPM has no problem resolving this:  % swift package resolve Fetching ssh://me@… Cloning ssh://me@… Resolving ssh://me@… at 0.0.1 In Xcode though, I get the line from the title: An unknown error occurred. username does not match previous request (-1) (by the way I have copied this by hand as the message could not even be copy & pasted) Any ideas how to solve this? Or even debug this any further? best Roddi
Posted
by
Post not yet marked as solved
2 Replies
472 Views
This looks like xcodebuild bug, but I just wanted to bring it up here as well. I've been having issues with this in our project and seen other people mentioning similar issue https://github.com/realm/realm-cocoa/issues/6814, so I've put together an example project that suffers from this issue. https://github.com/petrpavlik/CodeCoverageBugExample/tree/master This is unmodified app template generated by Xcode, where I've 2 swift packages that contain ObjC code - CocoaAsyncSocket and SDWebImage. I was able to replicate this with Realm package for instance, so it's not about these 2 particular packages. Running xcodebuild to run tests and collect code coverage xcodebuild "-workspace" "CodeCoverageBugExample.xcworkspace" "-scheme" "CodeCoverageBugExample" "build" "COMPILER_INDEX_STORE_ENABLE=NO" "test" "-destination" "id=2E465F79-A48A-4C32-BBE0-F1104A27E4C7" "-resultBundlePath" "Test.xcresult" "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" "GCC_GENERATE_TEST_COVERAGE_FILES=YES" fails with following error. duplicate symbol '___gcov_flush' in: 		/Users/petr/Library/Developer/Xcode/DerivedData/CodeCoverageBugExample-gictjvuwzgnjolaocdbqaotvidpx/Build/Products/Debug-iphonesimulator/SDWebImage.o 		/Users/petr/Library/Developer/Xcode/DerivedData/CodeCoverageBugExample-gictjvuwzgnjolaocdbqaotvidpx/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket.o ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Posted
by
Post not yet marked as solved
8 Replies
6.1k Views
When I use my repository with an "ssh://" URL and a private/public key, Xcode throws a "username does not match previous request (-1)" error. command line git (and every other GUI Git tool I tried) work without problems. Unfortunately this is also a problem for Swift Packages making them unusable for me. Before you ask: Of course "swift package …" works without problems on the command line. The problem exist consistently on every Xcode 12 version so far including Xcode 12b3. Seems like the devs put a bad git library into Xcode and now just leave it like that.
Posted
by
Post not yet marked as solved
1 Replies
762 Views
Hi, building swift package - https://github.com/SAP/cloud-sdk-ios-fiori with Xcode 12.1 and the following command xcodebuild -enableCodeCoverage YES -derivedDataPath Build/ -scheme FioriSwiftUI-Package -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=14.1,name=iPhone 11' clean build test results in the following error: Error: Mismatch between existing container extension: <DVTExtension 0x7fd732e56260: Swift User Managed Package Folder (Xcode.IDEFoundation.Container.SwiftPackageUserManagedFolder) from com.apple.dt.IDE.IDESwiftPackageSupport> and requested container extension: <DVTExtension 0x7fd732e56750: Swift Package Proxy (Xcode.IDEFoundation.Container.SwiftPackageProxy) from com.apple.dt.IDE.IDESwiftPackageSupport> for file path: <DVTFilePath:0x7fd738728c30:'/Users/d041771/git/cloud-sdk-ios-fiori/Build/SourcePackages/checkouts/observable-array'> Why? How is it possible to build with -derivedDataPath without requiring a xcodeproj file? Note Building without -derivedDataPath works Building with -derivedDataPath and specifying -project works but is not an option for us as the package shall embed localized resources (swift-tools-version 5.3) in the future and building with xcoceproj will not work then - https://developer.apple.com/forums/thread/650278
Posted
by
Post marked as solved
6 Replies
3.4k Views
I'm getting an error building my Mac app for both Apple Silicon and Intel, related to a Swift package dependency. The dependency is a pure Swift package (SwiftyXMLParser), and I'm bringing it into my app with a package dependency from the git repository URL. My app is configured to build standard architectures to run natively on both Apple Silicon and Intel. The build fails because it looks like the package manager only provides the active architecture, not a universal library, when the latter is configured. It happens when I set "Build Active Architecture Only" to NO (if it's set to YES it succeeds, but then the app won't run on the other architecture). In particular, if I build on my M1 mini, the error is Could not find module 'SwiftyXMLParser' for target 'x86_64-apple-macos'; found: arm64, arm64-apple-macos If I build on my x86 MBP, same failure but the error is opposite (no arm64, found: x86_64). So clearly SPM+Xcode can provide either architecture - is it possible for it to provide a universal lib? Or do I need to download the source of the package and build it through a more manual process?
Posted
by