Skip to content

Commit e825d86

Browse files
committed
Added CocoaUtils class with convenient dispatch_sync() and dispatch_async() methods for running code on the main thread.
1 parent 3d255b2 commit e825d86

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package ca.weblite.objc.util;
6+
7+
import ca.weblite.objc.NSObject;
8+
import static ca.weblite.objc.RuntimeUtils.sel;
9+
import ca.weblite.objc.annotations.Msg;
10+
11+
/**
12+
*
13+
* @author shannah
14+
*/
15+
public class CocoaUtils {
16+
17+
18+
public static void dispatch_async(final Runnable r){
19+
(new NSObject("NSObject"){
20+
@Msg(selector="run", like="NSObject.finalize")
21+
public void run(){
22+
r.run();
23+
}
24+
}).send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("run"), null, false);
25+
}
26+
27+
28+
public static void dispatch_sync(final Runnable r){
29+
(new NSObject("NSObject"){
30+
@Msg(selector="run", like="NSObject.finalize")
31+
public void run(){
32+
r.run();
33+
}
34+
}).send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("run"), null, true);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)