سؤال

this is an IOS code block on xcode throws an error at compiling time.
"Semantic issue:no viable overloaded ="

  ...
  ccColor3B c_=;
  static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
     c_=ccc3(0,0,0);
});
  ...

this is just an example.Im getting ZERO example values from another method that reads value from database. and thus I want to call only once the RGB values.

should I use old method ?or there is a solution using dispatch_once

my old method was:

...
static BOOL everCalled=NO;
ccColor3B c_;
if(!everCalled){
  c_=ccc3(0,0,[myClass myClassMethodForExample]);
  everCalled=YES;
}
...
هل كانت مفيدة؟

المحلول

You are attempting to write to a data type which is outside of the block; this is allowed but you have to use the __block keyword:

__block ccColor3B c_=;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
     c_=ccc3(0,0,0);
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top