title: AFNetworking change base url
body: <p>I am using AFNetworking.</p>
  
  <p>I would like to change baseURL manually.</p>
  
  <pre><code>+ (CustomHTTPClient*)sharedClient{
  static dispatch_once_t pred;
  static CustomHTTPClient *_sharedClient = nil;
  
  
  
  NSLog(@"ShareClient %@",_sharedClient);
  if (!_sharedClient)
  {
      _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"serverURL"]]];
      [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
  }
  else
  {
  
      NSLog(@"Delete ShareClient %@",_sharedClient);
      _sharedClient = nil;
  
      _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"serverURL"]]];
      NSLog(@"NEW ShareClient %@",_sharedClient);
      [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
  
  }
  
  
  return _sharedClient;
  }
  </code></pre>
  
  <p>Option 2:</p>
  
  <pre><code>+ (CustomHTTPClient*)sharedClient{
  static dispatch_once_t pred;
  static CustomHTTPClient *_sharedClient = nil;
  
  
  dispatch_once(&amp;pred, ^{
      _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"serverURL"]]];
      [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
  });
  
  return _sharedClient;
  }
  </code></pre>
  
  <p>Option 1: This will create shareclient everytime. So it will use correct (new) BaseURL all time.
  Option 2: only called onces so BaseURL will be same all time.</p>
  
  <p>Quation:What will be implication of using option 1 instead of Option 2?</p>
  
  <p>I have also check some other answers but would like to understand(in simple terms) why to use Dispatch_once and how to make dispatch_once get called multiple time?</p>
  
  <p><a href="https://stackoverflow.com/questions/11639480/">changing AFNetworking baseURL</a></p>