Skip to content

Using with @escaping #7

@gabrielsousaleal

Description

@gabrielsousaleal

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()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions