iOS Development

ios – Find out how to arrange a SwiftData + SwiftUI app with advanced fashions?

I’m a newbie in Swift. I’m attempting to construct a easy DnD Character sheet app. Right here is my simplified character mannequin.

@Mannequin
ultimate class Character {
    var identify: String
    var hitDice: Cube

    init(identify: String, hitDice: Cube) {
        self.identify = identify
        self.hitDice = hitDice
    }

}

class Cube {
    var quantity: Int
    var sides: Int

    init(_ quantity: Int, _ sides: Int) {
        self.quantity = quantity
        self.sides = sides
    }

}

After I construct the app, I get this error: No actual matches in name to occasion methodology 'setValue'. This doesn’t solely occur with lessons. Additionally it is the case for dictionaries. Looks as if any non-primitive sort. Might this have one thing to do with how these knowledge sort map for underlying coredata/sqlite knowledge varieties?

Then I flip Cube into Mannequin

@Mannequin
ultimate class Cube {
     // ...
}

The error goes away however I get this mysterious breakpoint

@Transient
personal var _$backingData: any SwiftData.BackingData<Cube> = Cube.createBackingData()

public var persistentBackingData: any SwiftData.BackingData<Cube> {
    get {
        _$backingData
    }
    set {
        _$backingData = newValue
    }
}

static var schemaMetadata: [SwiftData.Schema.PropertyMetadata] {
  return [
    SwiftData.Schema.PropertyMetadata(name: "number", keypath: Dice.number, defaultValue: nil, metadata: nil),
    SwiftData.Schema.PropertyMetadata(name: "sides", keypath: Dice.sides, defaultValue: nil, metadata: nil)
  ]
}

init(backingData: any SwiftData.BackingData<Cube>) {
  _number = _SwiftDataNoType()
  _sides = _SwiftDataNoType()
  self.persistentBackingData = backingData
}

@Transient
personal let _$observationRegistrar = Statement.ObservationRegistrar()

struct _SwiftDataNoType {
}

My app

import SwiftUI
import SwiftData

@essential
struct CharacterSheetApp: App {
    let modelContainer: ModelContainer
    
    init() {
        do {
            modelContainer = strive ModelContainer(for: Character.self)
        } catch {
            fatalError("Couldn't initialize ModelContainer")
        }
    }

    var physique: some Scene {
        WindowGroup {
            ContentView()
        }
        .modelContainer(modelContainer)
    }
}

What am I doing improper?

Credit: www.ismmailgsm.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button