Hi, I'm trying to modularise an existing project, and want to bring over some Obj-C classes verbatim from the main project (refactoring them and bringing them over to Swift is the end goal, but want to piece meal it so to avoid "big bang" like changes).
I've got a mixed Swift package working with the package setup below:
import PackageDescription
let package = Package(
name: "AccountOverview",
platforms: [
.iOS(.v13),
],
products: [
.library(
name: "AccountOverview",
targets: ["AccountOverview", "AccountOverviewObjC"]),
],
dependencies: [
.package(path: "Purchases")
],
targets: [
.target(
name: "AccountOverview",
dependencies: ["Purchases"]),
.target(
name: "AccountOverviewObjC",
dependencies: ["AccountOverview"],
publicHeadersPath: "include"),
.testTarget(
name: "AccountOverviewTests",
dependencies: ["AccountOverview"]
),
]
)
But when I go to use Swift in an Obj-C class in the AccountOverviewObjC
target, I can't seem to find a way to import anything from the Swift target. Forward declaring doesn't appear to magically work, and neither does importing the target with:
@import AccountOverview
.
The Swift classes I want to use can never be found. And they're annotated correctly - here is an example of a Swift class that can't be found:
import Foundation
@objcMembers
class PurchasesInfo_ObjC_Shim: NSObject {
let isPremiumUser: Bool
let isPremiumUpgradeWithoutSubscription: Bool
let willPremiumSubscriptionRenew: Bool
let subscriptionExpiryDate: Date?
init(isPremiumUser: Bool,
isPremiumUpgradeWithoutSubscription: Bool,
willPremiumSubscriptionRenew: Bool,
subscriptionExpiryDate: Date?) {
self.isPremiumUser = isPremiumUser
self.isPremiumUpgradeWithoutSubscription = isPremiumUpgradeWithoutSubscription
self.willPremiumSubscriptionRenew = willPremiumSubscriptionRenew
self.subscriptionExpiryDate = subscriptionExpiryDate
}
}
I have tried searching for this, and I've found lots of topics about using Obj-C classes in Swift, but nothing about vice-versa. Thanks in advance!