iphone - Returning a bool value using dispatch_async -


simple question time, i've made "utility" class in new app me call method in different uiviewcontroller.

i use class function that. i'm facing new problem, have check if icloud available or not , use :

+ (bool)isicloudavailable {      bool isbothicloudenabled = no;       bool isicloudavailable = no;       nsurl *ubiq = [[nsfilemanager defaultmanager]                    urlforubiquitycontaineridentifier:nil];     if (ubiq) {         isicloudavailable = yes;      } else {         isicloudavailable = no;      }      nsuserdefaults *ausericloud = [nsuserdefaults standarduserdefaults];     bool boolpref = [ausericloud boolforkey:@"icloudenabled"];      if (boolpref && isicloudavailable)     {         isbothicloudenabled = yes;     }     else {         isbothicloudenabled = no;     }      return isbothicloudenabled;  } 

and on uiviewcontroller use :

if ([utils isicloudavailable]) {... } 

urlforubiquitycontaineridentifier:nil must called on main thread, how can ? know dispatch_async not work on return function.

thanks

your uiviewcontroller should running on main thread dispatch should unnecessary. if you're calling uiviewcontroller method different thread, recommend run invocation of method using dispatch_async on main thread, rather doing in method itself. is, method calls in uiviewcontroller done on main thread.

despite that, blocks can set values outside scope:

bool iscloudavailable = no; dispatch_sync(dispatch_get_main_queue(), ^{     iscloudavailable = [utils isicloudavailable]; }); 

this block thread until main thread runs block.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -