Post

Replies

Boosts

Views

Activity

CPU Usage Mapkit
I wrote a SwiftUI app for the Mac that uses MapKit to display a map for a given address. It uses geocoding to convert a street address to latitude and longitude. I place a pin on the map at the actual latitude and longitude. I have noticed that the pin appears to move slightly back and forth or up and down while it is displayed. The program isn't doing any other calculations. I have noticed that if the map is not displayed, the Mac Activity Monitor shows that the application is not using any CPU resources, but when the map is displayed, Activity Monitor shows around 10%. I'm not sure what that 10% means because Activity Monitory says that the User is only using 1.5 - 2%. What is the CPU doing? Is it waiting for the user to move or zoom the map? Is there a way to disable that and have just a static map display?
0
0
564
Nov ’21
403 Error with URLSession.downloadTask (SwiftUI)
I wrote a program that can download an updated data file publicly available from the US Government's FCC website. The file is updated weekly. This week, I went to download the file with my program and it failed to download. I looked at the HTTPURLResponse parameter to the completion callback and it shows a statusCode of 403 (forbidden). The program is the same program as last week when it worked. I copied the exact URL that the program was trying to download to both Safari and the command line curl and both were able to download the file without issue on the same computer. I changed the program to try and download a different file from a different server and it downloaded fine. I tried running the same program on a different Mac and it failed also. I tried several times for over an hour with the same result. Browsing the web for a solution I see mention of clearing caches. How does one clear the caches for a SwiftUI program? Thanks, Mark
2
0
1.7k
Nov ’21
Compile for different macOS versions
I am learning Swift/SwiftUI and working on my first substantial (for me) macOS application. Since I was following current tutorials and WWDC videos, I ended up using some features that are only available in OSX 12. Is there a way to maintain one code base that can be compiled for different target versions? I think I'm looking for something like C/C++'s #ifdef that would include different pieces of code depending on the target OS version. Mark
2
0
1.3k
Nov ’21
Maps / Geocoding in SwiftUI
I have written a program in SwiftUI to display information from a database that includes the street address, but not the latitude and longitude. I've added a button that passes the street address to geocodeAddressString to get the lat & long and updates the map, but every time I click the button, even though the map appears to be displayed properly, I get a message in Xcode complaining "Modifying state during view update..." My view has a @State variable that holds a MKCoordinateRegion() for the map to display. The closure on completion of the geocode lookup updates that @State.     @State private var mapRegion = MKCoordinateRegion()          private func updateAddress() {         let index = data.zipCode.index(data.zipCode.startIndex, offsetBy: 5)         geocoder.geocodeAddressString("\(data.streetAddress) \(data.zipCode[..<index])") { result, error in             DispatchQueue.main.async {                 if let coordinate = result?.first?.location?.coordinate {                     mapRegion = MKCoordinateRegion (                         center: coordinate,                         latitudinalMeters: 750,                         longitudinalMeters: 750                     )                     place = IdentifiablePlace(lat: coordinate.latitude, long: coordinate.longitude)                     // print ("updating address")                 }             }         }     }
0
0
1k
Nov ’21
CPU Usage Mapkit
I wrote a SwiftUI app for the Mac that uses MapKit to display a map for a given address. It uses geocoding to convert a street address to latitude and longitude. I place a pin on the map at the actual latitude and longitude. I have noticed that the pin appears to move slightly back and forth or up and down while it is displayed. The program isn't doing any other calculations. I have noticed that if the map is not displayed, the Mac Activity Monitor shows that the application is not using any CPU resources, but when the map is displayed, Activity Monitor shows around 10%. I'm not sure what that 10% means because Activity Monitory says that the User is only using 1.5 - 2%. What is the CPU doing? Is it waiting for the user to move or zoom the map? Is there a way to disable that and have just a static map display?
Replies
0
Boosts
0
Views
564
Activity
Nov ’21
403 Error with URLSession.downloadTask (SwiftUI)
I wrote a program that can download an updated data file publicly available from the US Government's FCC website. The file is updated weekly. This week, I went to download the file with my program and it failed to download. I looked at the HTTPURLResponse parameter to the completion callback and it shows a statusCode of 403 (forbidden). The program is the same program as last week when it worked. I copied the exact URL that the program was trying to download to both Safari and the command line curl and both were able to download the file without issue on the same computer. I changed the program to try and download a different file from a different server and it downloaded fine. I tried running the same program on a different Mac and it failed also. I tried several times for over an hour with the same result. Browsing the web for a solution I see mention of clearing caches. How does one clear the caches for a SwiftUI program? Thanks, Mark
Replies
2
Boosts
0
Views
1.7k
Activity
Nov ’21
Compile for different macOS versions
I am learning Swift/SwiftUI and working on my first substantial (for me) macOS application. Since I was following current tutorials and WWDC videos, I ended up using some features that are only available in OSX 12. Is there a way to maintain one code base that can be compiled for different target versions? I think I'm looking for something like C/C++'s #ifdef that would include different pieces of code depending on the target OS version. Mark
Replies
2
Boosts
0
Views
1.3k
Activity
Nov ’21
Maps / Geocoding in SwiftUI
I have written a program in SwiftUI to display information from a database that includes the street address, but not the latitude and longitude. I've added a button that passes the street address to geocodeAddressString to get the lat & long and updates the map, but every time I click the button, even though the map appears to be displayed properly, I get a message in Xcode complaining "Modifying state during view update..." My view has a @State variable that holds a MKCoordinateRegion() for the map to display. The closure on completion of the geocode lookup updates that @State.     @State private var mapRegion = MKCoordinateRegion()          private func updateAddress() {         let index = data.zipCode.index(data.zipCode.startIndex, offsetBy: 5)         geocoder.geocodeAddressString("\(data.streetAddress) \(data.zipCode[..<index])") { result, error in             DispatchQueue.main.async {                 if let coordinate = result?.first?.location?.coordinate {                     mapRegion = MKCoordinateRegion (                         center: coordinate,                         latitudinalMeters: 750,                         longitudinalMeters: 750                     )                     place = IdentifiablePlace(lat: coordinate.latitude, long: coordinate.longitude)                     // print ("updating address")                 }             }         }     }
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21