I adopted just a few guides on-line exhibiting methods to create a package deal for swift, I created a repo at our gitlab and added the tags so I might import it correctly into different initiatives, all that appeared to work nice, however now in my mission I’ve imported the library into, I get errors in Xcode any time I attempt to use my library… “Can’t discover ‘ChartData’ in scope”
A fast instance of this might be in “MyLibrary” I’ve the next “Bundle”
import PackageDescription
let package deal = Bundle(
identify: "MyLibrary",
platforms: [.iOS(.v16), .macOS(.v14)],
merchandise: [
.library(
name: "MyLibrary",
targets: ["MyLibrary"])
],
targets: [
.target(name: "MyLibrary", path: "Sources"),
.testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"])
]
)
Easy, then I’ve within the “Sources” folder…
Contents of ChartData.swift…
import Basis
public class ChartData: Identifiable {
public val id: String = UUID().uuidString
public var quantity: Int16
public var timestamp: Date
public init(quantity: Int16, timestamp: Date) {
self.quantity = quantity
self.timestamp = timestamp
}
}
Good and easy. I then commit this all in git, add a tag (say 1.0.0) then push to my git repo with the tag.
In my working mission I add a package deal dependency utilizing my git url and password and all that great things, and I see the mission has been added correctly in Xcode as a result of I can see it in “Bundle Dependencies” on the backside of the file viewer.
So I create a brand new swift ui view and try to make use of ChartData
import SwiftUI
import MyLibrary
import Charts
struct ChartView: View {
let knowledge = ChartData(quantity: Int16(2300), timestamp: Date())
var physique: some View {
HStack {
}
}
}
And proper there on let knowledge = ...
I get the error Can't discover 'ChartData' in scope
I’ve tried altering my Bundle
within the MyLibrary
to be one thing slightly extra actual?
targets: [
.target(
name: "MyLibrary",
resources: [
.process("charts")
]
)
...
]
however that does not work both. Unsure why my mission can not seem to discover ChartData
in scope, since I’m importing MyLibrary
and it’s outlined and imported together with MyLibrary
Sorry if that is an apparent mistake on my half, I’m simply studying this and the one examples I might discover of constructing a library actually had 1 file with some static code in it.
Thanks, and sorry for the lengthy learn.