drag and drop cards

I have a @State transferable object how can I change the values? They did changed hat on ui

greeting fabian

Answered by Climber1987Muc in 802617022

i have fixit:

carddata was wrong: it need @published

I can change the values, but die ui dosen't show it

Could you show the code that is expected to display the object ? That would help to help…

This is my card data

//
//  RouteList.swift
//  BikeComputer
//
//  Created by Fabian Szukat on 18.08.24.
//
import Foundation
import SwiftUI
import UniformTypeIdentifiers


class CardData: Observable, Transferable, Codable, Hashable{
    
    var title: String
    var icon: String
    var text: String
    var height: CGFloat
    var width: CGFloat
    var warning: Bool
    var warningText: String
    private var id: UUID
    var localizedTitle: LocalizedStringKey {
        return LocalizedStringKey(title)
    }
    
    enum CodingKeys: String, CodingKey {
        case title
        case icon
        case height
        case width
        case warning
        case warningText
        case id
        case text
    }
    
    var localizedText: LocalizedStringKey {
        return LocalizedStringKey(text)
    }
    
    static func == (lhs: CardData, rhs: CardData) -> Bool {
        if rhs.hashValue == lhs.hashValue {
            return true
        }
        return false
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        id = try container.decode(UUID.self, forKey: .id)
        title = try container.decode(String.self, forKey: .title)
        text = try container.decode(String.self, forKey: .text)
        width = try container.decode(CGFloat.self, forKey: .width)
        height = try container.decode(CGFloat.self, forKey: .height)
        icon = try container.decode(String.self, forKey: .icon)
        warning = try container.decode(Bool.self, forKey: .warning)
        warningText = try container.decode(String.self, forKey: .warningText)
     }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)        
        try container.encode(id, forKey: .id)
        try container.encode(title, forKey: .title)
        try container.encode(text, forKey: .text)
        try container.encode(width, forKey: .width)
        try container.encode(height, forKey: .height)
        try container.encode(icon, forKey: .icon)
        try container.encode(warning, forKey: .warning)
        try container.encode(warningText , forKey: .warningText)
    }
    
    init(){
        self.id = UUID()
        self.title = ""
        self.icon = ""
        self.text = ""
        self.height = 100
        self.width = 200
        self.warning = false
        self.warningText = ""
        
    }
    
    public func hash(into hasher: inout Hasher) {
        return hasher.combine(id)
    }
    
    static var transferRepresentation: some TransferRepresentation {
       
        CodableRepresentation(contentType: .carddata)
        
      }
}

    

This is my view

//
//  RouteList.swift
//  BikeComputer
//
//  Created by Fabian Szukat on 18.08.24.
//

import SwiftUI
import SwiftData
struct RouteView: View {
    @Environment(\.modelContext) private var modelContext
    @Query(sort: \Route.name) var routes: [Route]
    var body: some View {
        NavigationSplitView {
            List{
                if routes.isEmpty {
                    Text("No Entries avaible")
                }else{
                    ForEach(routes) { route in
                        NavigationLink{
                            RouteDetail(route: route)
                                
                        } label: {
                            RouteRow(route: route)
                        }.deleteDisabled(route.readonly).disabled(route.locked)
                    }.onDelete(perform: { indexes in
                        for index in indexes {
                            let route = routes[index]
                            modelContext.delete(route)
                          
                        }
                    })
                }
            }   .toolbar {
                EditButton()
            }
        } detail: {
            Text("Select a Route")

        }.navigationTitle("Routen")
         
    }
}

#Preview {
    RouteView()
}
   func addPointToRoute(loc: CLLocation ) {
        let point = Point()
        point.speed = loc.speed
        point.altitude = loc.altitude
        point.datetime = loc.timestamp
        point.speedAccuracy = loc.speedAccuracy
        point.course = loc.course
        point.horizontalAccuracy = loc.horizontalAccuracy
        point.verticalAccuracy = loc.verticalAccuracy
        let coordinate = Coordinates()
        coordinate.latidude = loc.coordinate.latitude
        coordinate.longitude = loc.coordinate.longitude
        //point.coordinate = coordinate
        
        /*if(self.point.altimeters.count > 0){
            point.altimeters.append(self.point.altimeters.last ?? Altimeter())
        }*/
         
        if(recording && !pausedRecording ){
            addpoint(point: point)
        }
        self.point = point
        updateCard(titel: "", text: "")
    }
    private func updateCard(titel: String, text:String){
        for (index, element) in cards.enumerated() {
            cards[index].text = "text"
            
        }
    }


..```
I tried so much sorry 
Accepted Answer

i have fixit:

carddata was wrong: it need @published

drag and drop cards
 
 
Q