Hi there,
I'm facing an issue in an Xcode project for an iOS app related to importing Swift packages.
I have a couple of local Swift packages that define extensions on Apple frameworks and/or define functions that make use of types exposed in such frameworks.
For example, I have an extension on Logger
like this:
import Foundation
import os
public extension Logger {
static let authentication = Self(subsystem: subsystem, category: "authentication")
static let payments = Self(subsystem: subsystem, category: "payments")
// …
private static let subsystem = "com.myCompany.myApp"
}
and top-level functions like this:
import Foundation
import Testing
public func verifySuccess<T, E: Error>(
_ result: Result<T, E>,
_ comment: Comment? = nil,
sourceLocation: SourceLocation = #_sourceLocation
) {
// …
Issue.record("Failed to verify \(comment ?? "result")", sourceLocation: sourceLocation)
}
The problem is that, back in the iOS app code, the compiler complains with "Cannot find 'Logger' in scope"
or "Missing required module 'Testing'"
when I import my local package and try to make use of these affordances:
import MyLocalPackage
// import Testing
struct SomeType {
@Test
func somethingHappens() {
// …
// This fails if I don't import "Testing" above
verify(.success(true))
}
}
I was somehow under the impression that by importing my package, its transitive dependencies (i.e. os
and Testing
) would be automatically imported as well.
With that in mind, I have two initial questions:
- Is my assumption wrong?
- Is there a way to specify in my local package that frameworks like
os
orTesting
should be (automagically?) imported? Or do I have to import them explicitly every time?
To be honest, I could live with the fact that whenever I want to use any of these extensions/functions, I have to import the Apple frameworks as well.
But the annoying part of all this is that the compiler also complains in places where my local package is imported, even when I'm not using any of these extensions/functions:
import MyLocalPackage
import XCTest
final class SomeTests: XCTestCase {
func testThatSomethingHappens() {
// No use of 'Testing' related here, the compiler still
// complains that it's missing
XCTAssert(true);
}
}
Note that I need to import my local package because it contains many other extensions (e.g. for XCTest
), not just for Testing
.
I would also appreciate a bit of guidance to understand what's causing that.
Thank you!