title: Initializing Singleton async iOS
body: <p>I have a singleton named <code>YelpService</code>. Its responsible for retrieving data from Yelp. Of course, each API call must be authorized. The problem is that auth process is async. It would be very redundant if I had to check if yelp client was authorized each time before use of <code>YelpService</code>. How can I get around this? </p>
  
  <p>Also, if I add authentication logic inside a method with completion handler and nest inside other method that actually make API calls I get a error: <code>Command failed due to signal: Segmentation fault: 11</code></p>
  
  <p>What is a safe and efficient way of storing Yelp client so I can make API calls?
  I know its bad to make network calls in init. </p>
  
  <pre><code>class YelpService {
  
      static let _shared = YelpService()
  
      private let clientId = "id"
      private let clientSecret = "secret"
  
      var apiClient: YLPClient?
  
      init() {
  
          YLPClient.authorize(withAppId: clientId, secret: clientSecret) { (client, error) in
              guard error == nil else {
                  print("YELP AUTH ERROR: \(error!.localizedDescription)")
                  return
              }
              guard let client = client else {
                  print("YELP AUTH ERROR: CLIENT IS NIL")
                  return
              }
              self.apiClient = client
          }
      }
  }
  </code></pre>