PS the id parameter is no longer required in List(dataModel.getBucketList(), id:.name) { item in since I made BucketItem Identifiable in the Extension.
Post
Replies
Boosts
Views
Activity
PS I meant to get rid of the cost property in BucketItem, because I essentially replaced it with a computed value totalCost. In this simple app, the cost of a buckelist item is the sum of the associated cost items, therefore the original cost property on BucketItem is redundant - and potentially a consistency problem.
OK, I’ll post some in the morning ( about 12 - 14 hours from now ).
Struth, whudah thought Strine would be such an issue. Oh well, she’ll be roight Mate.
Thanks Cobber.
The reference to MacOS Beta 2 was a typo error, as a result of my septuagenarian deteriorating eyesight (& brain). I'm using the latest beta.
Have you managed to get CoreData working, on both the Watch and the Phone? I've been trying out CoreData and could now help you if needs be. Regards, Michaela
Sorry for the delay: there seems to have been a problem with the forum software and I was getting an error when attempting to respond. You only format the dates at the point of displaying them to the user: for all other purposes, you must use the original dates for comparisons and computations - except where you want specific information about the local date-time e.g. whether it's morning or not, in which case you use the Calendar functions with the date (not the formatted string).
??? Other comments and my examples that we exchanged disappeared from the thread. Have you got things working now the way you want?
My understanding is that you need to store Goal, with its title, count1, count2 and creation time, and that, as the app gets used, more and more Goals are stored. If you only ever store ONE goal on the watch, before it is sent to the phone, then you might be able to use UserDefaults to reload title, count1, count2 and creation time each time the watch app relaunches - before data are sent to the phone. However, "The defaults system allows an app to customize its behavior to match a user’s preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed." - Apple Documentation. What you're suggesting are not preferences, but cumulative data. I wouldn't use UserDefaults this way. When I have a small amount of data that only gets added to by appending, I store it as a text file with comma separated values. For anything else I use SQLite and/or CloudKit. You will be using CoreData on the phone, so (as I've stated) you can use the same code on the watch to store your data there. CoreData, SQLite and CloudKit are all complex (to begin with) but data persistence is an essential skill that must be learned. :). Regards, Michaela
let currentHour = Calendar.current.component(.hour, from: Date())
if currentHour < 12 {print("now is morning")}
This gets the hour, as an Integer, from the current local time, i.e. the Calendar function converts the UTC time to the user's current timezone and summertime (or not) settings.
I suggest that you experiment with Date formatting and with Calendar in a Playground.
No, comparison of Date types is done on the UTC date-time. If the date-time of your user's timezone is important in decision making, e.g. how many times did the user do X before 10am each day, then you'd need to use the Calendar functions https://developer.apple.com/documentation/foundation/calendar
Your data are more complex than I gathered from your original post, i.e. title:number. You're now describing a struct with various properties, which include an array of counts. If this is correct, then there is a way of sending that via transferUserInfo but UserDefaults would not be an appropriate way of storing the data on the watch. Is only one 'title', 'count1', 'count2', 'creation date' struct sent at a time, or an array of them? Is there a variable number of counts per title on a given creation date? The answers to these questions determine how best to store data on the watch (if really needed) and how to transmit to the phone. I can't do much more to help until tomorrow afternoon Eastern Australia time.
Angel?? No, I'm an elderly, retired IT person (50+ years work) with lots of time on my hands :)
Good luck Frank. If you get stuck, then I'd be happy to help out (e.g. sample code). I'm retired and currently stuck at home in a COVID lockdown, so I've plenty of time on my hands :)
I’d prefer to post working code on here: I understand your requirement and the code will be short enough to fit in a reply, but without the Coredata part. What version of Xcode, iOS & WatchOS do you use and do you use SwiftUI? If you use SwiftUI, do you generate apps with or without an AppDelegate? These days I prefer “pure” SwiftUI apps, I.e. without the app delegate. I can probably make a start tomorrow morning (12 hours time) if you want, and you get those answers to me.
The watch connectivity sample code you refer to (above) contains far more than you need, so it’s not a good starting point.