Background:
This code is based on dated PM example written by Mattt years ago.
Goal: I'm trying to get importing to work, so I created a basic package; based on Mattt's working package. His example works flawlessly. Hence attempting to recreate from scratch.
Scenario:
I've created a basic package.
I've added a Dependency.
I've added an 'import <Dependency' in package source but I'm getting the following build failure:
Here's the actual code:
// 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: "RicPackage",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "RicPackage",
targets: ["RicPackage"]),
],
dependencies: [
.package(name: "PlayingCard", url: "https://github.com/apple/example-package-playingcard.git", from: "3.0.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "RicPackage",
dependencies: ["PlayingCard"]),
.testTarget(
name: "RicPackageTests",
dependencies: ["RicPackage"]),
]
)
Question:
Why is this happening?
What am I missing?
Gremlins?
I played around with the package header to notice changes in syntax acceptance. Then I reverted to the latest and did a recompile.
This time it SUCCEEDED.
I did a Xcode restart just to be sure this is true.
I rebuild... again SUCCEEDED.
Note: be sure to be aware of the package header the says the version of the package. The package syntax (amongst other things) change/version.
Related
I have a function called .readSize that, in SwiftUI, allows a child View to report its size to its parent View. The function is included in an extension to the View struct. Before upgrading to Xcode 14 this package was working. Now, at Xcode 14.0.1, it does not work. Xcode simply tells me that Text has no member .readSize. When I check, the Project Navigator is showing the package and I can open the module containing .readSize.
(The logic for reporting child size is taken from the Five Stars blog).
When I click on the project in the Project Navigator, click on the Project field and click the "Package Dependencies" tab then the "packages" section is empty. If I tap on the "+" symbol then Xcode presents a popover with an "Add Local" button. Clicking that will allow me to find the package and add it. That process, however, merely duplicates the package in the Project Navigator. In the Package Dependencies tab the "packages" section is still empty.
I have tried some of the standard cleanup approaches, such as removing the package, performing a clean, restarting Xcode, and then re-introducing the package with File -> Add Packages. I get the same error.
At a guess, it may be that my package is no longer defined property. The manifest reads as follows:
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ViewExtensions",
platforms: [.iOS("13.0")],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ViewExtensions",
targets: ["ViewExtensions"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ViewExtensions",
dependencies: []),
.testTarget(
name: "ViewExtensionsTests",
dependencies: ["ViewExtensions"]),
]
)
I'm at a standstill. Is there some way to debug why Xcode will not allow me to add my package under Package Dependencies?
I want to create a Swift Package with binary targets which has sub dependencies. As the binary targets not support sub dependencies out of the box, I have created a wrapper target that depends on both the binary framework and other dependencies as described here
Package has a target called Logger.
CocoaLumberjack is a dependency of Logger.
Logger I have generated as XCFramwork and hosted in a server as publicly accessible. Below I have added a screenshot of the Xcode project which I used to generate XCFramwork.
Please refer to the Package manifest file.
import PackageDescription
let package = Package(
name: "spmpoc",
products: [
.library(
name: "Logger",
targets: ["LoggerTarget"]),
],
dependencies: [
.package(
name: "CocoaLumberjack",
url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
from: "3.6.1"),
],
targets: [
.target(
name: "LoggerTarget",
dependencies: [.target(name: "LoggerWrapper",
condition: .when(platforms: [.iOS]))]
),
.target(
name: "LoggerWrapper",
dependencies: [
.target(name: "Logger", condition: .when(platforms: [.iOS])),
.product(name: "CocoaLumberjack", package: "CocoaLumberjack")
]
),
.binaryTarget(name: "Logger", url: "https://mypath.com/Logger.xcframework.zip", checksum: "mychecksum")
]
)
I am able to add Swift package via Swift Package Manager, but When I try to import Logger module build error occured as ..../Logger.framework/Modules/Logger.swiftmodule/arm64-apple-ios.swiftinterface:4:8: No such module 'CocoaLumberjack'
Could someone please help me to figure out what could be the issue here?
Error
XCFramwork code snapshot for reference
Update:
I have change import to #_implementationOnly import in Logger.swift. Now in the generated .swiftinterface files does not contains the "import CocoaLumberjack" hence, compile error went away. However, app crashing because it is still looking for CocoaLumberjack.framework but its not available. '.../Library/Developer/Xcode/DerivedData/TestSPMApp-gfbagjtzjrrkjuathrrienvklwxs/Build/Products/Debug-iphonesimulator/CocoaLumberjack.framework/CocoaLumberjack' (no such file)
CocoaLumberJack added to Logger framework as a pod dependency. It seems, inside the Pods-Logger.xcconfig file it is referring to CocoaLumberjack.framework. I believe this causes the issue now.
I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import for the dependencies in your code to #_implementationOnly import
E.g.
#_implementationOnly import CocoaLumberjack
You can read more about #_implementationOnly here
I am creating a simple Library Swift Package:
import PackageDescription
let package = Package(
name: "dpo-sdk-spm",
platforms: [
.iOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "dpo-sdk-spm",
targets: ["dpo-sdk-spm"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "dpo-sdk-spm",
dependencies: ["Alamofire"]),
.testTarget(
name: "dpo-sdk-spmTests",
dependencies: ["dpo-sdk-spm"]),
]
)
I specifically did not create a project file, as working with that in source control is a pain - and its not required to develop a library that will be consumed in a iOS App, that will have the necessary build settings etc. My Library was created using swift package init --type library and here is the structure:
I specified under the platforms node iOS V10, then pushed the package to my git repo. I added my git account to Xcode, created a App project, added my package via Xcode 11's built in SPM and had no issues, however trying to build I got:
Showing All Messages The package product 'Alamofire' requires minimum platform version 10.0 for the iOS platform, but this target supports 8.0
I did specify the platform and version in my Package.swift, why is the build pipeline ignoring this variable?
I'm having a second thought using multiple products inside SPM. Here is the thing.
I’ll provide two products in the package. One is “Tool” and the other one is “ToolNetworking”.
The first one has some swift classes, nothing special, no dependencies at all.
The second one also has some swift logic, but a dependency on Alamofire lib.
Here is the config:
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "Tool",
platforms: [.iOS(.v11)],
products: [
.library(name: “Tool", targets: [“Tool"]),
.library(name: “ToolNetworking", targets: [“ToolNetworking"])
],
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .exact("5.1.0"))
],
targets: [
.target(
name: "Tool",
path: "Sources",
exclude: ["Networking"]
),
.target(
name: "ToolNetworking",
dependencies: ["Tool", "Alamofire"],
path: "Sources",
sources: ["Networking"]
)
],
swiftLanguageVersions: [.v5]
)
When I want to install the package, I can choose between the two. If I select ToolNetworking, it will also install Alamofire dependency.
For Tool product I only want SPM to install my code, no dependencies. Here is my question. How can I exclude Alamofire when I install only Tool product since I didn't define a dependencies field?
Thanks
A first step would be to upgrade to Swift 5.2. The Swift Package Manager shipped with Swift 5.2 starts to implement exactly this behaviour (as described in SE-0226).
However, since it's not fully implemented yet, it could be that Xcode will still check out Alamofire. It should not link it in the end, though. So if you only use the Tool product, the resulting binary will not have any traces of Alamofire inside it :-)
I am working on swift cocoa touch framework to create reusable framework from mobile application.
my framework need to use jwt project from https://github.com/vapor/jwt.git
i tried to create Package.swift and then add .package(url:"https://github.com/vapor/jwt.git", from: "3.0.0") and then run swift package resolve
in my code, i import jwt library like this
import JWT
import Foundation
but i got the error No such module 'JWT'
i am newbie on swift, can someone help please?
my Package.swift is here
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "edoc-sdk-swift",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "edoc-sdk-swift",
targets: ["edoc-sdk-swift"]),
],
dependencies: [
.package(url:"https://github.com/vapor/jwt.git", from: "3.0.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "edoc-sdk-swift",
dependencies: ["JWT"]),
.testTarget(
name: "edoc-sdk-swiftTests",
dependencies: ["edoc-sdk-swift"]),
]
)
You should check two things:
Module name is JWT, not jwt.
Check that your .target in Package.swift contains "JWT" in dependencies
thanks all guys for the feedback.
now i can solve the problem, and i write the solution to this blog
https://piggyman007.blogspot.com/2018/12/create-swift-framework-and-include-some.html