-
Notifications
You must be signed in to change notification settings - Fork 13
Using with @escaping #7
Copy link
Copy link
Closed
Description
Sometimes I need to use some swift function that needs a completion (@escaping), as I'm running a DispatchQueue.main.async.
example:
func getGeolocation() -> String {
var params: [String: AnyObject] = [:]
let service = ServicoGeolocation()
service.execute(showAlertPermission: true) { (location, error) in
params = [
"latitude": location.coordinate.latitude,
"longitude": location.coordinate.longitude,
"accuracy": location.horizontalAccuracy,
"timestamp": location.timestamp.description
] as [String : AnyObject]
}
return params.description
}
In this case I will always have the return [:] in javascript. Is there a way to pass this completion to javascript? Like:
@objc protocol JavaScriptProtocol {
func getGeolocation(completion: @escaping(String) -> Void)
}
Or make the return happen just after service.execute()?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels