Post

Replies

Boosts

Views

Activity

Comment on SwiftUI MapKit Map - Selecting Points of Interest
I was finally able to get it to work in the following case: @State private var selectedItem: MKMapItem? @State private var selected: Feature? Map(position: $position, selection: $selectedFeature) { } .mapFeatureSelectionDisabled { _ in false } .mapFeatureSelectionContent { item in Marker(item.title ?? "", coordinate: item.coordinate) } I had previously passed selectedItem to the selection parameter. Is it possible to allow selection of MKMapItems and MapFeatures?
3w
Comment on SwiftUI MapKit Map - Selecting Points of Interest
I have the selection parameter of the map set to the following and I'm able to select MapFeatures but not Markers representing search results that are an array of MKMapItem. When tapping the Markers, they are not selected and instead the Map simply zooms in closer to the Marker. @State private var selection: MapSelection? Is there something additional that needs to be specified for the Map to allow the MapFeatures and Markers to be selected?
2w
Comment on SwiftUI MapKit Map - Selecting Points of Interest
Thanks again, Ed. I had most of this code but the secret sauce that I was missing was setting the .tag modifier to MapSelection(result). I'm now able to select MapFeatures as well as search results. I additionally (per other post) need to get the MapFeature for the given MKMapItem, so I can use the same image and color regardless of if the user tapped the MapFeature or used search.
2w
Comment on Store SwiftUI Color in SwiftData
The code you have provided is essentially the same as what I had tried previously and using the same test with Photoshop, the original color #FBAA1D also became #FFAB00. The difference comes down to the fact that you need to convert the floating point values to integers and store those within the hex encoded String. I'm looking for a way to store the Color in SwiftData such that there is no data loss and the stored color is identical to the original color. Thanks for following up though!
2w
Comment on Get SwiftUI Image Data
I'm getting the image from a MapFeature in a SwiftUI app that makes extensive use of MapKit. The user can add places as favorites and I would like to save the image and background colors from the MapFeature into SwiftData so they can both be used in the list of favorite places.
1w
Comment on Store SwiftUI Color in SwiftData
I appreciate the follow up and I did try your code which was very similar to code that I had tried previously. The issue with any approach that is based on encoding Color using Integer values, such the RGB components of #FFAB00. The rounding of the original CGFloat values to Integers involves some loss of precision. In most cases this isn't an issue but I'm looking for the best way to store the original Color as precisely as possible, either as a Data or individual Float values. Thanks again!
1w
Comment on Store SwiftUI Color in SwiftData
I found this article that discusses using a ValueTransformer which can then be used with SwiftData to store UIColor values. https://www.avanderlee.com/swift/valuetransformer-core-data/ You simply reference the transformer within your model: @Attribute(.transformable(by: UIColorValueTransformer.name.rawValue)) var color: UIColor?
1w
Comment on Store SwiftUI Color in SwiftData
It turns out that the difference in the color is because the color being saved to SwiftData is being displayed correctly with the dark mode adjustment. Somehow, when I'm reading the color from SwiftData and using it in another view, the color is rendered as it would be in light mode or without the dark mode adjustment. The UIColorValueTransformer is working as expected. I need to determine why the color discrepancy with regard to the dark mode adjustment, even with dark mode enabled throughout.
1w
Comment on Store SwiftUI Color in SwiftData
Final comment. I have built a test to provide Apple to understand the cause of the issue. When the original color is provided by the SwiftUI ColorPicker then it is persisted and created again correctly. When the color is instead provided from a MapFeature, the color is different after being persisted and read from SwiftData. Again, thanks for all the responses to my original question. The issue only occurs in dark mode.
1w
Comment on Get SwiftUI Image Data
I tested this approach and was able to restore the image from the Data stored in SwiftData. Unfortunately though, the .foregroundStyle(.black.opacity(0.75)) modifier had no effect and the image remained white in color. This would work if the user only viewed the app with the light appearance but not if the user had dark appearance enabled. Definitely a step closer to what is needed though. Just need to determine how to apply the darker foreground style.
1w