i have fixit:
carddata was wrong: it need @published
Post
Replies
Boosts
Views
Activity
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
I can change the values, but die ui dosen't show it
the Project file was defect. so I create a new one. that was all
@B347
thank you so much :)
update: After 30 seconds the task broke up.... do you have any ideas?
Greeting
Hello ,
You have to go into your project.
Click on your Bluetooth_test app and click “About”.
In the Customs IOS Target table, click Plus and look for Privacy - Bluetooth Always Usage Description. In the Value column, enter your reason for wanting this permission.
@Claude31 thank you its works
For the first problem:
I have found out the .onAppear works only onetime.
there is a replacement?
Greeting Fabian
Thank you for information :)
Hello @Claude31,
I forget to implement a decoder but I missing any error :(
thank you for your help :)
greeting
Try to use a line vertically without bending
Hello,
This is a simple environmental object. This Object has only two variables.
a getter and init method
I get only a warning:
Conditional downcast from 'Data?' to 'Data' does nothing
import Foundation
class RouteList: ObservableObject {
@Published var routes: [RouteObject]
let saveKey = "SavedData"
init() {
if let data = UserDefaults.standard.data(forKey: saveKey) as? Data {
print(data)
if let decoded = try? JSONDecoder().decode([RouteObject].self, from: data) {
routes = decoded
return
}
}
routes = []
}
func save() {
if let encoded = try? JSONEncoder().encode(routes) {
UserDefaults.standard.set(encoded, forKey: saveKey)
}
}
}
protocol ProtocolName: ObservableObject {
var routes: [RouteObject] { get }
}
i fixted thank you....
it was a design error
Hello @eskimo,
that is what I get:
longitude CLLocationDegrees 0
latitude CLLocationDegrees 0
self BikeComputer.Location 0x0000000303ee7f60
log