I’d like to create a macro for GCD calls like for example:
dispatch_async(dispatch_get_main_queue(), ^{
stuff....
});
the macro could look something like this:
main(^{…})?
Not sure how to write it. Any suggestion?
thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can define macros like this:
First one will invoke the code asynchronously on unspecified thread (do all long running tasks using it) and the second one will invoke the block asynchronously on the main thread (do all UI related stuff using it).
You can combine both. Let’s say you want to grab something from the network and update UI, you can write:
You add curly braces to make Xcode indent the code properly.
Please note where retain/release calls are made. This is powerful technique which will make your code readable.