title: iOS start Background Thread
body: <p>I have a small sqlitedb in my iOS device. When a user presses a button, I fetch the data from sqlite &amp; show it to user.</p>
  
  <p>This fetching part I want to do it in a background thread (to not block the UI main thread). I do this like so - </p>
  
  <p><code>[self performSelectorInBackground:@selector(getResultSetFromDB:) withObject:docids];</code></p>
  
  <p>After the fetching &amp; a little bit of processing, I need to update the UI. But since (as a good practice) we should not perform UI updation from background threads. I call a <code>selector</code> on mainthread like so - </p>
  
  <p><code>[self performSelectorOnMainThread:@selector(showResults) withObject:nil waitUntilDone:NO];</code></p>
  
  <p>But my App crashes in the first step. i.e. starting a background thread. Is this not a way to start background threads in iOS? </p>
  
  <p><strong>UPDATE 1:</strong> After <code>[self performSelectorInBackground....</code> I get this stacktrace, no info what so ever - </p>
  
  <p><img src="https://i.stack.imgur.com/C1AaS.png" alt="enter image description here"></p>
  
  <p><strong>UPDATE 2:</strong> I even tried, starting a background thread like so - 
  <code>[NSThread detachNewThreadSelector:@selector(getResultSetFromDB:) toTarget:self withObject:docids];</code> but still I get same stacktrace.</p>
  
  <p>Just so that I clarify, when I perform this operation on main thread everything runs smooth...</p>
  
  <p><strong>UPDATE 3</strong> This is the method I am trying to run from background </p>
  
  <pre><code>- (void)getResultSetFromDB:(NSMutableArray *)toProceessDocids
  {
      SpotMain *mirror = [[SpotMain alloc] init];
      NSMutableArray *filteredDocids = toProceessDocids;
  
      if(![gMediaBucket isEqualToString:@""])
          filteredDocids = [mirror FetchDocIdsForMediaBucketWithDocID:filteredDocids mBucket:gMediaBucket numRes:-1];
      if(![gMediaType isEqualToString:@""])
          filteredDocids = [mirror FetchDocIdsForMediaType:filteredDocids mediaType:gMediaType numRes:-1];
      if(![gPlatform isEqualToString:@""])
          filteredDocids = [mirror FetchDocIdsForPlatformID:filteredDocids platformId:@"1" numRes:-1];
  
      self.resultSet = [mirror FetchObjectFromDocid:filteredDocids];
      [filteredDocids release];
      [mirror release];
  
      [self performSelectorOnMainThread:@selector(showResults) withObject:nil waitUntilDone:NO];
      return;
  }
  </code></pre>