title: multithread search design
body: <p>Dear Community. I like to understand a little task, which have to help me improve performance for my application.
  I have array of dictionaries, in singleton area with objects NSDictionary and keys
  code 
  country
  specific</p>
  
  <p>I have to receive country and specific values from this array.
  My first version of application was using predicate, but later i find a lot of memory leaks and performance issues by this way. Application was too slow and don't empty very quickly a memory stack, coming to around 1G and crash.</p>
  
  <p>My second version was little bit more complicated. I was filled array in singleton area with objects per one code and function, which u can see bellow.</p>
  
  <pre><code>-(void)codeIsSame:(NSArray *)codeForCheck;
  {
  //@synchronized(self) {
  NSString *code = [codeForCheck objectAtIndex:0];
  
  if ([_code isEqualToString:code]) 
  {
      code = nil;
      NSUInteger queneNumberInt = [[codeForCheck objectAtIndex:1] intValue];
      NSLog(@"We match code:%@ country:%@ specific:%@ quene:%lu",_code, _country,_specific, queneNumberInt);
      [[ProjectArrays sharedProjectArrays].arrayDictionaryesForCountryCodesResult insertObject:_result atIndex:queneNumberInt];
  }
  
  code = nil;
  //}
  return;
  }
  </code></pre>
  
  <p>The way to receive necessary issues is a :</p>
  
  <pre><code>SEL selector = @selector(codeIsSame:);
  [[ProjectArrays sharedProjectArrays].myCountrySpecificCodeListWithClass makeObjectsPerformSelector:selector withObject:codePlusQueueNumber];
  </code></pre>
  
  <p>This version working much better, no memory leaks, very quickly, but too hard to debug. Sometimes i receive empty result, i tried to synchronize thread jobs, but it still not work stable. The main problem in this way is that in strange reason sometimes i don't have result in my singleton array. I tried to debug it, using index of array for different threads, and have result that class just missed answer.</p>
  
  <p>Core data don't allow me to make copy of main MOC and for multithreading design i can't using it (lock and unlock is not good idea, and that's way product too much error in lock/unlock part of code.</p>
  
  <p>Maybe anybody can suggest, what i can do better in this case? I need a best way to make decision which will work stable, will be easy to coding and understand it?</p>
  
  <p>My current solution is using NSDictionary, where is a keys is a code and under that code i have dictionary with country/specific. Working fine as well, but don't decide a main task - using core data if u need multiply access from too many threads to the same data.</p>