I want to make an MacOS app with Swiftdata but there is a problem. When i create a new project and select swiftdata xcode provides example of swiftdata. When I launch the app on my Mac I get the following error in the console:
dyld[61569]: Symbol not found: _$s9SwiftData6SchemaC16PropertyMetadataVMa Expected in: <A7F2CF0D-77A3-3F13-BE59-DCBAC4C53133> /System/Library/Frameworks/SwiftData.framework/Versions/A/SwiftData
And this :
dyld`:
0x7ff8190208a8 <+0>: movl $0x2000209, %eax ; imm = 0x2000209
0x7ff8190208ad <+5>: movq %rcx, %r10
0x7ff8190208b0 <+8>: syscall
-> 0x7ff8190208b2 <+10>: jae 0x7ff8190208bc ; <+20>
0x7ff8190208b4 <+12>: movq %rax, %rdi
0x7ff8190208b7 <+15>: jmp 0x7ff818fb50db ; cerror_nocancel
0x7ff8190208bc <+20>: retq
0x7ff8190208bd <+21>: nop
0x7ff8190208be <+22>: nop
0x7ff8190208bf <+23>: nop
with the following sentence :
Thread 1: signal SIGABRT
So my model code is :
import Foundation
import SwiftData
@Model
class Paint{
var id: UUID
var name: String
var heigt: Int
var width: Int
var category: String
var year: String
var price: Int
var isSold: Bool
init(name:String, heigt:Int, width: Int, category: String, year: String, price: Int, isSold : Bool){
self.id = UUID()
self.name = name
self.heigt = heigt
self.width = width
self.category = category
self.year = year
self.price = price
self.isSold = isSold
}
}
func addPaint(name:String,
heigt:Int,
width: Int,
category: String,
year: String,
price: Int,
isSold:Bool,
context: ModelContext) {
let newPaint = Paint(name: name,
heigt: heigt,
width: width,
category: category,
year: year,
price: price,
isSold: isSold)
print("item save sucessfully")
context.insert(newPaint)
}
The contentView :
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var context
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button("add"){
addPaint(name: "test",
heigt: 1,
width: 1,
category: "",
year: "2023", price: 10, isSold: false, context: context)
}
}
.padding()
}
}
and finally the main :
import SwiftUI
import SwiftData
@main
struct syhomApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(for: Paint.self)
}
}
please help me !!
I have a solution : use CoreData instead but I really want to do it with SwiftData.
The thing is and I create a SwiftData projet for iOS every thing is working well (why ?) ...