Hi Drew, my suggested solution does NOT work. I've used computed properties several times in my apps, but not for sorting, and I just assumed (incorrectly) that the solution would work - but it doesn't: Coredata does not allow sorting by computed property. There's no compiler error, just a crash. Normally I check my answers on the forum before posting, but on this occasion I made a faulty assumption. So, I apologise for wasting your time. Nor can you just change the attribute type to Date from String - this would require a Migration. Best wishes and regards, Michaela
Post
Replies
Boosts
Views
Activity
Hi Drew, my suggested solution does NOT work. I've used computed properties several times in my apps, but not for sorting, and I just assumed (incorrectly) that the solution would work - but it doesn't: Coredata does not allow sorting by computed property. There's no compiler error, just a crash. Normally I check my answers on the forum before posting, but on this occasion I made a faulty assumption. So, I apologise for wasting your time.
Nor can you just change the attribute type to Date from String - this would require a Migration.
Best wishes and regards, Michaela
Oops, I forgot to mark the realDate var as public. It might work without being public, but I doubt it. Regards, Michaela
Thank you for your kind words Harry: much appreciated. I'll answer your questions in another Answer, rather than a comment, because the formatting is easier and better.
I've gone back to using UIViewRepresentable for all my mapping needs, except that NSGesturerecognizer seems not to work in certain cases with MacOS and Mac Catalyst apps crash if the app uses polylines.
There's been a lot of pressure from developers for SwiftUI Map to have the same capabilities as MapKit, so I expect (hope?) that future releases will make life easier. That said, I'm having problems with a MacOS mapping app, SwiftUI and MapKit coordinator, related to a bug somewhere in Apple code. One of my tasks in the next day or two is to collect all the evidence and submit a bug report.
Nice solution to making the annotations!! The Map facility within SwiftUI is very limited, basically restricted to showing annotations at known coordinates, e.g. giving it coords you already have somewhere in your data (or per your idea). There's no way of plotting a track either ( a poly line). To put an annotation on the map with a tap or long-press requires 1) a gesturerecognizer in your SwiftUI View (easy) and 2) a method to convert the press's view x,y location to map coordinates. Unfortunately the latter is only available in the MapKit framework (i.e.not SwiftUI), which then requires a coordinator from SwiftUI to MapKit and some fairly (unfairly??) complex code to manage everything. I've done MapKit coordinators, but there's a lot of code and might be too much to put in a post.
I was in a hurry to get this sample done before visitors arrived, so it's not as robust as it could be. It would be better to initiate the dataTable in DataModel as @Published var dataTable = DataFrame(). With this initialisation, the reference to model.dataTable! in ContentView doesn't need to be (shouldn't be) force unwrapped i.e. just use model.dataFrame. Also, with a large input csv file it would be better to load as a background task (via DispatchQueue) and rely on the @Published var dataTable to populate the SwiftUI List.
Ooo, that's good! Also useful knowledge for me, in case I need realtime communication in the future. I've done a lot of work with route tracking (e.g. running (as in exercise) app, so would be happy to help out if needs be.
Well done! It's good to see another retireee doing app development. I'd already assumed you are very tech savvy, although, yes, Swift and particularly SwiftUI can be hard to get one's head around (was for me, anyway) after years of procedural programming. Sharing of the phone and watch ViewModal code is the best way to go (though potentially more complex), especially if both devices will have the same functionality. Normally I use a separate Framework (library) for all of my Data Model (ViewModel) code, with OS specific code as needs be. This is because most of my apps now are Multiplatform (Mac, iPad, iPhone, Watch and sometimes TV), with data sharing via the Cloud: my watch apps are now standalone, i.e. not tethered to the phone. However, your need appears to be for reliable realtime communication, which probably wouldn't suit a Cloud approach
OK, will do - sometime later today (I'm in Australia so just getting started on the day)
In your Watch's session didReceiveUserInfo function you need to update the ViewModel variable (i.e. data that get displayed) using DispatchQueue.main.async { update the var } as you probably did in the phone app if using my sample code. This is because communication sessions are run on a background queue, whereas views (and their associated data) can only be updated on the main queue.
Good luck and regards, Michaela
Mmm, I haven't had that message before, but I'm aware that it's been a problem for others from time to time. I suggest checking if your session (instance of WCSesssion) returns .ispaired == true on the phone immediately after your session gets activated. If it returns false, then see if the iPhone and Watch really are paired. It might also be an idea to check all other aspects of the paired device information as per the documentation https://developer.apple.com/documentation/watchconnectivity/wcsession. What versions of Xcode, iOS and watchOS are you using? If needs be, I can try to replicate the problem here. Regards, Michaela
Are you using SwiftUI or UIKit? If SwiftUI, the sample code I provided earlier works: make sure you follow what I said for the phone app. The key aspects are: 1) the Phone Data Model must be an ObservableObject, 2) you must use @Published on the variable (count) that you want synced in your view, 3) you must update the @Published count in the data model from incoming watch data by using DispatchQueue.main.async 4) the SwiftUI view must declare the data as @ObservedObject var ........
Oh, and I'm a lady - so just call me Michaela - not Uncle.
My question is why Apple provides a feature and then says it’s not been implemented. My feedback will be for them to either implement it, or remove it. Right now it’s wasting developers’ time.