0

I'm using a framework that uses the function below, I tried converting it to swift using a website, but it was unable to do so. Any help would be greatly appreciated!

[databaseChanges enumerateDocumentChangeDetailsUsingBlock:^(METDocumentChangeDetails *documentChangeDetails, BOOL *stop) {
      ...
    }];

3 Answers 3

1

Try this:

databaseChanges.enumerateDocumentChangeDetailsUsingBlock({
    (documentChangeDetails:METDocumentChangeDetails,
     stop:UnsafeMutablePointer<ObjCBool>) -> Void in
    // ...
})
Sign up to request clarification or add additional context in comments.

Comments

1

Is the framework available in swift? If it's not you will have to create a bridging header as described here:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

Then you will be able to easily figure out how to call this function using Xcode's auto complete.

Just type:

databaseChanges.enu

And xcode will give you the way it should be called.

Edit:

I assume you are using this library. Which offers support for swift. So your problem is purely about how to write the block in Swift 3 syntax. matt's answer has the solution for that.

Comments

1

In Swift 3:

databaseChanges.enumerateDocumentChangeDetails { details, stop in

}

It might suggest all sorts of other syntactic noise (types for details and stop, etc.), but this distills it down to the essentials, using type inference to keep the code nice and expressive.

And if you want to stop it, it's

stop.pointee = true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.