Swift Package Manager failing after updating to Xcode 14 - ios

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?

Related

Getting "No such module" error when trying to create an xcframework with dependencies

I tried different ways with different configurations and cannot make it run. Here is what I tried while creating the xcframework:
Add 1 framework dependency as pod
Add 1 framework dependency as Swift package (MKRingProgressView) and created also a swift package marking the dependency in the package dependency as follows:
name: "FirstFramework",
platforms: [
.iOS(.v15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "FirstFramework",
targets: ["FirstFramework"]),
],
dependencies: [
.package(url:
"https://github.com/maxkonovalov/MKRingProgressView.git",
from: "2.3.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.
.binaryTarget(
name: "FirstFramework",
path: "./Sources/FirstFramework.xcframework")
]
Set build libraries for distribution to YES
I am always getting the error "No such module MKRingProgressView" when adding my framework to a Test project, so its not recognising the dependency of my framework.
Any ideas?

Swift package has bitcode disabled

I created a really simple Swift package, that contain only a few Objective-C source files, but when I try to build another project that it, it fail compiling because:
ld: bitcode bundle could not be generated because 'MySwiftPackage.o' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build file 'MySwiftPackage.o' for architecture arm64
I also tried to force Bitcode to be enable by adding settings:
cSettings: [.define("OTHER_CFLAGS", to: "-fembed-bitcode")] and .define("ENABLE_BITCODE", to: "YES") with no luck.
How can I identify what is causing the bitcode to be disabled ?
Here is my package.swift:
let package = Package(
name: "MySwiftPackage",
platforms: [.iOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MySwiftPackage",
targets: ["MySwiftPackage"]),
],
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: "MySwiftPackage",
publicHeadersPath: "Public",
cSettings: [
.headerSearchPath("Internal")
])
]
)

Swift Package build failure. Remedy?

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.

Swift Package: Module not found

I have created a non-syslib C module (let's call it CModule) and packaged it with Swift Package Manager such that my code is in $(package_directory)/Sources/CModule and my Package.swift in the aforementioned parent directory contains:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "CModule",
products: [
.library(
name: "CModule",
type: .dynamic,
targets: ["CModule"]),
],
targets: [
.target(
name: "CModule",
dependencies: [],
path: "Sources",
cSettings: [
.headerSearchPath("CModule")])
]
)
The package compiles without errors, but after adding it to another Swift project with File -> Swift Packages -> Add Package Dependency and inputting the local repo (file:///Users...etc), which does give me the right target, doing import CModule within this new project gives me the Module not found error.
I have already relaunched Xcode, did Clean Build Folder followed by a normal Build, and tried another approach such as it was described in How to make custom C code into a SwiftPM package?
Try these steps:
1. File -> Swift Packages -> Reset Package Caches
After packages are reset, follow below steps:
2. File -> Swift Packages -> Update to Latest Package Versions

Swift SPM Package minimum iOS version not propagating

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?

Resources