Same issues here since sonoma my macbook is acting wired , it’s plug for more than few hours , sometime it charge but when battery is drain low it sometime doesn’t charge…. never happen before sonoma
@apple team please solve this issue i don’t want my macbook to be spoil because of an upgrade OS.
Post
Replies
Boosts
Views
Activity
Sorry guys I should have finish the tutorial and it is actually useful if you want to change a full vstack with animation ;)
got my answer it’s useful if you want to group things and make any animate it.
if someone want to add something please add , today that’s the only purpose I see thanks to this tutorial.
as for the Hstack agree that one is useful.
email adress upvote03_ballade at iCloud dot com
Hi lol I've just click the same here , I believe this button is to just say that you are not alone thinking about this and I agree for you own post it doesn't make sense to see the button but at least to see the number of people whom have the same issues as the post, I believe this is for APPLE to look at the most same here and try to answer those first kind of a "" oo there is 150 same here on this issues looks like we need to release a new Beta update or fix our bugs lol"
Sharp eye, I did not see that my own post do not have this same here button
I did not know Git can allow me to still work only computer I thought GIT everything I do is visible by everyone in the world, while I may build some app for my company in future and I want to keep some data private, that's Why I wanted to avoid Git, but as you explain if Git allow my work to remain local then I will try git, I was also a bit reluctant because there is so many push pull ,commit, fetch, stage,cherry pick on so on so I'm very lost... lol
here is my button change data :
import SwiftUI
struct DatePickerStyle: View, Observable {
@Environment(TimesheetCalculation.self) var timesheetCalculation
@State var date = TimesheetCalculation().date
@State var dateRange = TimesheetCalculation().dateRange
var body: some View {
@Bindable var timesheetCalculation = timesheetCalculation
HStack {
Button {
timesheetCalculation.date = timesheetCalculation.date.addingTimeInterval(-86400)
} label: {Label("8h", systemImage: "arrowtriangle.backward.fill")
.labelStyle(.iconOnly)
.offset(x:5)
.scaleEffect(2)
.foregroundStyle(Color(red: 0.937, green: 0.937, blue: 0.942) )}
DatePicker(
"Start Date",
selection: $timesheetCalculation.date,
in: timesheetCalculation.dateRange,
displayedComponents: [.date]
).padding(.horizontal)
Button {
timesheetCalculation.date = timesheetCalculation.date.addingTimeInterval(86400)
} label: {Label("8h", systemImage: "arrowtriangle.forward.fill")
.labelStyle(.iconOnly)
.offset(x:-5)
.scaleEffect(2)
.foregroundStyle(Color(red: 0.937, green: 0.937, blue: 0.942) )
}
}.labelsHidden()
}
}
struct DatePickerStyle_Previews2: PreviewProvider {
static var previews: some View {
//#Preview
DatePickerStyle()
.environment(TimesheetCalculation())
}
}
and here is my Project Struct
import Foundation
import SwiftUI
import CoreLocation
struct Project: Hashable, Codable,Identifiable {
var id: Int //UUID = UUID()
var name: String
var shortname: String
var leftPMtime: Int
// var projectRow: Int // inside projects ( why claude add this ??
// var city: String
// var country: String
var state: String
var description: String
var isFeatured: Bool
var isSpecific: Bool
var isFavorite: Bool
var isTeco: Bool
var coordinates: Coordinates
// var isHourSet : [Bool] // ### To store for each hour of the project
// private enum CodingKeys : String, CodingKey {
// case name, shortname, leftPMtime, isTeco
// }
var category: Category
enum Category: String, CaseIterable, Codable {
case foodAndBaverage = "Food & Baverage"
case NutritionAndBioscience = "Nutrition & Bioscience"
}
var buisness_model: Buisness
enum Buisness: String, CaseIterable, Codable {
case BM1 = "BM1"
case BM2 = "BM2"
case BM3 = "BM3"
}
var customer: CustomerCat
enum CustomerCat: String, CaseIterable, Codable {
case Nestle = "Nestle"
case IFF = "IFF"
case FFI = "FFI"
case IFFCO = "IFFCO"
case Abbott = "Abbott"
case Mondelez = "Mondelez"
case Internal = "Internal"
}
private var imageName: String
var image: Image {
Image(imageName)
}
var featureImage: Image? {
isFeatured ? Image(imageName + "_feature") : nil
}
var locationCoordinate: CLLocationCoordinate2D {
CLLocationCoordinate2D(
latitude: coordinates.latitude,
longitude: coordinates.longitude)
}
struct Coordinates: Hashable, Codable {
var latitude: Double
var longitude: Double
}
}
as you can see UUID and isSet is not working when I place them inside I believe due to JSON way
Here is the remaining code and questions :
why do you use string ( or maybe I change in between and I ws the one using String at first ^^sorry if yes haha
are you trying to use @binding here to clear all the button to false regardless of the project and it;s the only way to achieve it ?
this 2 line of code timesheetCalculation.checkRemainingHours(isSet: true) keep telling me that it will never be used but actually it's beeing use and working : warning from Apple is Result of call to 'checkRemainingHours(isSet:)' is unused
timesheetCalculation.checkRemainingHours(isSet: true)
//
// HourButton.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 9/2/24.
//
import SwiftUI
struct HourButton: View,Identifiable, Observable { //This Identifiable is
@Environment(TimesheetCalculation.self) var timesheetCalculation
//MARK: - Variable & Constants
var id: Int = 1001 //CLAUDE USE STRING
@State var isSet: Bool
// CLAUDE IUSE BINDING @Binding var isSet: Bool // A Binding, as we change the value and want it updated in TimeKeyInRow
var value: Float
//MARK: - Body
var body: some View {
@State var timesheetCalculation = timesheetCalculation
HStack {
Button {
if value <= timesheetCalculation.remainingHour || isSet == true {
isSet.toggle()
print("clic on Project : \(id) an turn to : \(isSet) for \(value)h")
if isSet == true {
timesheetCalculation.hourchoosen = value
timesheetCalculation.checkRemainingHours(isSet: true)
timesheetCalculation.hourchoosen = value
timesheetCalculation.cvsrecordedtrackingcodek(idofthiskeyin: id, valueOfThisKeyin: value, itemsisSet: isSet)
} else {
timesheetCalculation.hourchoosen = value
timesheetCalculation.checkRemainingHours(isSet: false)
timesheetCalculation.cvsrecordedtrackingcodek(idofthiskeyin: id, valueOfThisKeyin: value, itemsisSet: isSet)
}
} else {
// Warning message
print("Please understand that you cannot work more than 8h")
}
} label: {
Label("" , systemImage: isSet ? "circle.fill" : "circle")
.labelStyle(.iconOnly)
.foregroundStyle(isSet ? .blue : .gray)
}.id(id)
}
}
}
//MARK: - Preview
struct HourButton_Previews: PreviewProvider {
static var previews: some View {
//#Preview {
let timesheetCalculation = TimesheetCalculation()
HourButton(id: 1001, isSet: false, value: 3).environment(timesheetCalculation)
}
}
//MARK: - Extension
extension Array where Element: Equatable {
mutating func removeFirstOccurrence(of element: Element) {
if let index = firstIndex(of: element) {
remove(at: index)
}
}
}
here is the logic code
//
// TimesheetCalculation.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 12/2/24.
//
import Foundation
import SwiftUI
@Observable
class TimesheetCalculation {
var date = Date()
let dateRange: ClosedRange<Date> = {
let calendar = Calendar.current
let startComponents = DateComponents(year: 2024, month: 1, day: 1)
let endComponents = DateComponents(year: 2024, month: 12, day: 31)
return calendar.date(from:startComponents)!
...
calendar.date(from:endComponents)!
}()
var isSet: [Bool] = [false, false, false, false, false,false,false,false]
let listOfPossibleHours: [Float] = [0.5,1,2,3,4,8]
let listOfPossibleHoursText: [String] = [".5","1","2","3","4","8"]
var hourchoosen: Float = 0
var remainingHour: Float = 8
var cvsrecordedtrackingcodek: String = ""
var cvsrecordedtrackingcodekall: [String] = []
func checkRemainingHours(isSet: Bool) -> Float {
if isSet == true {
remainingHour = remainingHour - hourchoosen
return remainingHour
} else {
remainingHour = remainingHour + hourchoosen
return remainingHour
}
}
func cvsrecordedtrackingcodek(idofthiskeyin id:Int,valueOfThisKeyin value:Float,itemsisSet isSet:Bool) {
let newstring = String("ProjectID:\(id) Number of Hours: \(value) For Day: \(date.formatted(date: .abbreviated, time: .omitted))")
if isSet == true {
cvsrecordedtrackingcodekall.append(newstring)
} else {
cvsrecordedtrackingcodekall.removeFirstOccurrence(of: newstring)
}
print(cvsrecordedtrackingcodekall)
}
}
here is my Modeldata
//
// ModelData.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 3/2/24.
//
import Foundation
import Observation
@Observable
class ModelData {
var projects: [Project] = load("ProjectData.json")
var hikes: [Hike] = load("hikeData.json")
var profile = Profile.default
var isSet: [Bool] = [false, false, false, false, false,false,false,false]
var features: [Project] {
projects.filter { $0.isFeatured }
}
var categories: [String: [Project]] {
Dictionary(
grouping: projects,
by: { $0.category.rawValue }
)
}
var buisness: [String: [Project]] {
Dictionary(
grouping: projects,
by: { $0.buisness_model.rawValue }
)
}
var customers: [String: [Project]] {
Dictionary(
grouping: projects,
by: { $0.customer.rawValue }
)
}
}
func load<T: Decodable>(_ filename: String) -> T {
let data: Data
guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle.")
}
do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}
do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}
Here is a SetTimeKeyInView which is use to set the row, to have a comprehensible discussion with you.
I'm trying to make our conversation more clear and more focus oriented by splitting my code
bring filternonTECOproject here
this codecompletly change but same philosophy as previous post explain you want to use the ProRow as your row to simplify the code but for what ?
ForEach($filteredProjects, id: \.id) { $project in
TimeKeyInRow(id: project.shortname, projects: $projects, projectNum: project.projectRow)`
import Foundation
import SwiftUI
//MARK: - Variable & Constants
struct SetTimeKeyInView: View {
@Environment(ModelData.self) var modelData
let projects = ModelData().projects // Now need a State var to be able to modify later I did not do that need to check with Claude
@State var isSet = ModelData().isSet // look similar that what Claude is truing to do in Project(isSet) but not working when I wanted to put in Project Structure ( error waring was cannot Parse Thread 1: Fatal error: Couldn't parse ProjectData.json as Array<Project>:
var filteredNonTECOProjects: [Project] {
// removeTECO project
modelData.projects.filter { project in
!project.isTeco
}}
//MARK: - Body
var body: some View {
VStack(spacing: 20) {
BlankKeyInRow()
// Claude Code completly changed ForEach($filteredProjects, id: \.id) { $project in
// TimeKeyInRow(id: project.shortname, projects: $projects, projectNum: project.projectRow)
// }
ForEach(Array(filteredNonTECOProjects.enumerated()), id: \.offset) { (row, project) in
if project .isSpecific {
Divider()
Divider()
TimeKeyInRow(id: project.id, project: project, isSet: $isSet[row])
} else {
TimeKeyInRow(id: project.id, project: project, isSet: $isSet[row])}}
}.listStyle(.inset)
.environment(\.sizeCategory, .extraExtraExtraLarge)
}
}
//MARK: - Preview
struct SetTimeKeyInView_Previews2: PreviewProvider {
static var previews: some View {
//#Preview
SetTimeKeyInView()
.environment(ModelData())
.environment(TimesheetCalculation())
}
}
Hi Claude, few questions here or point here
I have change the id from string to id for all id but I'm getting confuse on what id is actually doing in our code since we use the Id\ offset of the creation of array...
You uses in TimekeyinRow @Binding var projects: [Project] which is for all project I use in in the project list when we combined all the list
I change all double to float because float as less digit therefore I believe use less memory I hope
your foreacharray uses 2 new property projectNum and allHoursFalse ( isHourSet) butI believe my buttonHoursbutton already collect all those information Right ?
What you are doing now is the meaning of what I was trying to say when I was saying the the code as a glitch because seems like with the actual program I have I cannot collect and reset all button in one click
I do not use onappear fonction at all ( I'm not sure what it's doing but my program work without it
the button you add I would like to add it somewhere else on the list I will share the screenshot on the next tread which I try to make and call it ClearRow()
import SwiftUI
struct TimeKeyInRow: View,Identifiable {
@Environment(TimesheetCalculation.self) var timesheetCalculation
//MARK: - Variable & Constants
var id: Int //CLAUDE use String
var project: Project
// @Binding var projects: [Project] // we pass all projects as well as the projectNum to handle. That eases the update of the project properties
@Binding var isSet: Bool
// CLAUDE ADD var projectNum: Int // The project displayed in the row
// let allHoursFalse = [false, false, false, false, false, false] // To simplify code writing, we hard code: there are 6 hours defined
let listOfPossibleHours = TimesheetCalculation().listOfPossibleHours// double is 15 digit decimal while Float is only 6 digit < I'm only one digit therefore I use Float
//MARK: - Body
var body: some View {
HStack {
Text(project.shortname.paddedToWidth(10)) // Text(projects[1].shortname)
.font(.custom("Menlo", size: 16))
.multilineTextAlignment(.trailing)
.frame(width: 120.0) // <<-- To get proper alignment
Spacer()
ForEach(listOfPossibleHours, id: \.self) { hour in
HourButton(id: project.id, isSet: isSet, value: hour)
}
// ForEach(Array(listOfPossibleHours.enumerated()), id: \.offset) { (index, hour) in
// HourButton(id: "\(projects[projectNum].shortname)", isSet: $projects[projectNum].isHourSet[index], value: hour) // HourButton has changed, to pass value of isSet for each hour
// }
Text("\(project.leftPMtime)")
// CLAUDE CHANGE here to collect a project number Text("\(projects[projectNum].leftPMtime)")
.font(.custom("Menlo", size: 16))
.multilineTextAlignment(.leading)
.frame(width: 45) // <<-- To get proper alignment
// CLAUDE ADDED BUTTTON TO SET ALL TO FALSE Button {
// projects[projectNum].isHourSet = allHoursFalse
// } label: {
// Text("all off")
// }
}
}
}
struct TimeKeyInRow_Previews: PreviewProvider {
static var previews: some View {
//#Preview {
let projects = ModelData().projects
TimeKeyInRow(id: projects[2].id, project: projects[2], isSet: .constant(false))
.environment(TimesheetCalculation())
}
}
extension String { // To align text
func paddedToWidth(_ width: Int) -> String {
let length = self.count
guard length < width else {
return self
}
let spaces = Array<Character>.init(repeating: " ", count: width - length)
return self + spaces
}
}
struct BlankKeyInRow: View {
var body: some View {
HStack {
Text(" ") // Text(projects[1].shortname)
}
}
}
struct ClearRow: View {
@Environment(TimesheetCalculation.self) var timesheetCalculation
var project: Project
@Binding var isSet: Bool
let listOfPossibleHours = TimesheetCalculation().listOfPossibleHours// double is 15 digit decimal while Float is only 6 digit < I'm only one digit therefore I use Float
var body: some View {
HStack {
ForEach(listOfPossibleHours, id: \.self) { hour in
HourButton(id: project.id, isSet: false, value: hour)
}
}
}
}
Thanks I will create a new tread for my new point and answer all your question, ? But I have figure out the above points you mentioned and already started to clean the code even further I which there could be a way for me to share my project to you without every time creating long-lasting thread but I really really apreacite the support you constantly give to me
Hi @Claude31 now that I fully understant this code above I believe there Is a big glitch to this solution, because I'm not sure I will need it or not but what if I want to let's say switch all the button back to false ? since the IsSet was parameter by an array but this array is gone even if I use @State for the duration of the tuple finishing I have no way to retrieve the status of the actual button right ? meaning that I do not have a way to give me a full view of the status of all the IsSetbutton in the timekeyinList ? or I may miss something here ?
Thanks @Claude31 feels like you part of swift development team ;)
with you on my side I have thousands of great app free in the Apple Store to make people life easier and less busy ;) to spend more time with people and familly ;) hahah thanks man appreciate really
Hi @Claude31 , seems like I will call you Master soon ^^, lol ok for the photo I'm not sure how I will reduce them but I will find the way , as for what I want in term of binding and state is to link the Value feedback to another swift file here :
@Observable
class TimesheetCalculation {
let maxHourPerDay: Double = 8
var hourchoosen: Double = 0
var totalhourbooked: Double = 0
var remainingHour: Double = 8
var cvsrecordedtrackingcodek: String = "id,value,shortprojectName,day"
func checkRemainingHours() -> Double {
return remainingHour
}
And here is the whole logic I want to build once I manage to insert my own code below and after this print
// Logic to create, every single button has an ID and a value
//first is to collect all the clicked button and make sure he cannot clic more than 8 hours
//but first it to link the variable in TimesheetCalculation class, which is not working so far
//once I manage to connect this the following logic will apply
//maxHourPerDay = 8h
//hourchoosen = value of clic button
//totalhourbooked = value + value + value - value (if click false)
//remainingHour = maxHourPerDay - totalhourbooked
//cvsrecordedtrackingcodek will be to keep track of previous day, converted in cvs for future excel export
//checkRemainingHours function to automaticly calcuation each time the button has been clic , normlay once the logic will be set I will just put this checkRemainingHours into the action button .
// the is also anothe logic that I need to put in place.
if remainingHour - new Value being click is less than 0 then the button will not be able to toggle, meaning that he will not be able to key-more than 8h `````
the issues with UUID in Project.swift is that when I change from id to UUID I get teh following message
Type 'Project' does not conform to protocol 'Decodable' the moment I add this
private enum CodingKeys : String, CodingKey {
case name, shortname, leftPMtime, isTeco
}
and this code for every single line that is into the Project.swift
& 2. Cannot automatically synthesize 'Decodable' because 'id' does not have a matching CodingKey and does not have a default value
3. Cannot automatically synthesize 'Decodable' because 'state' does not have a matching CodingKey and does not have a default value
...
9. Cannot automatically synthesize 'Decodable' because 'category' does not have a matching CodingKey and does not have a default value
as for the list{ } if I add the List in this code , now it's even worth than before since I change all to Int even the id of button is now Int to match ID of the project all the button for every single row become active, but the moment I remove the list everything works fine
//
// TimeKeyinList.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 9/2/24.
//
import SwiftUI
struct TimeKeyinList: View {
@Environment(ModelData.self) var modelData
let projects = ModelData().projects // Now need a State var to be able to modify later I did not do that need to check with Claude
@State var isSet: [Bool] = [false, false, false, false, false,false,false,false] // explain to claude that I I ahve more proejct in future and I don't increare this list then the app crash ... not very sure why but i believe it's due to the number of row link with the number of project dispaly
var filteredNonTECOProjects: [Project] {
// removeTECO project
modelData.projects.filter { project in
!project.isTeco
}}
var body: some View {
VStack {
HStack {
Text("TIME KEY_IN")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
Spacer()
Text("8h")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
}.padding()
Spacer()
VStack(spacing: 5){
HStack(alignment: .top) {
Text(" Project Name")
.multilineTextAlignment(.leading)
.lineLimit(2)
.frame(width: 120.0) // <<-- To get proper alignment
Text(".5h")
Text("1h")
Text("2h")
Text("3h")
Text("4h")
Text("8h")
Text("Time Left")
.multilineTextAlignment(.trailing)
.lineLimit(2)
.frame(width: 50)
}
VStack(spacing: 20) {
BlankKeyInRow()
ForEach(Array(filteredNonTECOProjects.enumerated()), id: \.offset) { (row, project) in
if project .isSpecific {
Divider()
TimeKeyInRow(id: project.id, project: project, isSet: $isSet[row])
} else {
TimeKeyInRow(id: project.id, project: project, isSet: $isSet[row])
}
}
}
.listStyle(.inset)
DatePicker(selection: .constant(Date()), label: { Text("Date") })
}
.environment(\.sizeCategory, .extraExtraExtraLarge)
.labelsHidden()
Spacer()
.onAppear() {
// <<-- Added
for (row, project) in filteredNonTECOProjects.enumerated() {
isSet[row] = !project.isTeco
}
}
Spacer()
}
}
}
struct TimeKeyinList_Previews2: PreviewProvider {
static var previews: some View {
//#Preview
TimeKeyinList().environment(ModelData())
}
}
Hi All issues is because I was not implementing a special ID to each of the button for every single one but to the full row creation.
This was due to two specific thing, first one I did not implement UUID or id to each button, but even after implementing this special ID for each button I realised that creating a list was a mistake too {} hope this post can help many new or skilled persons and once again thanks to Claude to help me make it happen @Claude31