ios – Can’t move perform of kind ‘([CLPlacemark]?, (any Error)?) async throws -> Void’ to parameter anticipating synchronous perform kind
[ad_1]
I’ve written this code:
In step one, I learn an Excel file that incorporates the addresses of the buildings as a string.
LABE | HAUS | Gemeindename |
---|---|---|
Hasenwinkel | 14 | Braunschweig |
The Excel file is much like the desk above.
I need to learn the addresses inside a loop and get the coordinates of the addresses (Lat, Lengthy) utilizing CLGeocoder. Utilizing the snapshotImage perform, I give the coordinates as enter to the perform, and if there may be image, I need to save that image of the goal handle with its handle title.
However I get the next errors:
1.Can’t move perform of kind ‘([CLPlacemark]?, (any Error)?) async throws -> Void’ to parameter anticipating synchronous perform kind
2. Invalid conversion from throwing perform of kind ‘([CLPlacemark]?, (any Error)?) async throws -> Void’ to non-throwing perform kind ‘([CLPlacemark]?, (any Error)?) -> Void’
let columnTypes: [String: CSVType] = ["LABE": .string,
"HAUS": .string,
"Gemeindename": .string]
let path = Bundle.principal.url(forResource: "Adresse", withExtension: "csv")!
let choices = CSVReadingOptions(
hasHeaderRow: true,
ignoresEmptyLines: true,
delimiter: ";"
)
let end result = attempt DataFrame(contentsOfCSVFile: path,rows: 0..<50, varieties: columnTypes,choices: choices)
enum LookaroundError: Error {
case unableToCreateScene
}
func snapshotImage(for coordinate: CLLocationCoordinate2D) async throws -> UIImage {
guard let scene = attempt await MKLookAroundSceneRequest(coordinate: coordinate).scene else {
throw LookaroundError.unableToCreateScene
}
let choices = MKLookAroundSnapshotter.Choices()
choices.measurement = CGSize(width: 1000, top: 500)
return attempt await MKLookAroundSnapshotter(scene: scene, choices: choices).snapshot.picture
}
var handle: String = ""
for row in end result.rows {
if row["HAUS"] == nil {
handle = "(row["LABE"] ?? <#default worth#>) (row["Gemeindename"] ?? <#default worth#>)"
} else {
handle = "(row["LABE"] ?? <#default worth#>) (row["HAUS"] ?? <#default worth#>) (row["Gemeindename"] ?? <#default worth#>)"
}
print(handle)
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(handle){ (placemarks, error) in
guard
let placemarks = placemarks,
let location: CLLocationCoordinate2D = placemarks.first?.location?.coordinate
else{
return
}
var picture = attempt await snapshotImage(for: location)
var url = attempt FileManager.default
.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appending(element: "(handle).png")
attempt picture.pngData()?.write(to: url)
}
}
Ideally, I need to learn the addresses on this loop and save an image of them utilizing their coordinates.I haven’t got a lot expertise in Swift programming. Does anybody have an concept easy methods to resolve the code drawback?
[ad_2]