-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to pass function? #269
Comments
The So to call it, you'd do something like this: use block2::{Block, ConcreteBlock}; // or the old `block` crate
let handler = ConcreteBlock::new(|| {
// Code to run on completion.
// This closure can capture values, but since `completionHandler` is executed asynchronously, the captured
// values must be `Send + Sync`.
});
// Put the block on the heap
let handler = handler.copy();
// Ensure that the block has the correct type (no arguments, `void` return type)
let handler: &Block<(), ()> = &handler;
let _: () = unsafe { msg_send![http_cookie_store, cookie: cookie_data, completionHandler: handler] }; |
(I know that the API that the |
Thanks. I will try. |
It's working as expected. |
@madsmtm Is the example above still how one is supposed to pass a block as an argument? It doesn't seem to work with the published crates ( With the following simplified example, I get an error: EDIT: Oh, I just realized the issue was due to using an outdated/conflicting versions of |
Hi, How can I pass a function to msg_send and call it?
For example, I want to pass a function to the completionHandler of setCookie method in WKHTTPCookieStore like in the code below.
I don't know how to define function.
I'm actually using objc, but this community is more active so I asked here.
The text was updated successfully, but these errors were encountered: