Cycling using singleton in Swift
<p>I have a singleton class:</p>

<pre><code>class SomeManager {
    static let sharedInstance = SomeManager()

    let serverService  = SomerServerService()
    let musicService = SomeMusicService()
}
</code></pre>

<p>I try to use </p>

<pre><code>class SomeMusicService
{
  let serverService = SomeManager.sharedInstance.serverService //here seems I get cycle.
}
</code></pre>

<p>Should I use lazy or some other initialization.</p>

<p>As you can see <code>let musicService = SomeMusicService()</code> initializes an object and then in the same object <code>SomeMusicService</code> it tries to call <code>sharedInstance</code> of <code>SomeManager</code> singleton to get another service at start.</p>

<p>So this is a full listing:</p>

<pre><code>import Foundation

class ServerService
{
  func downloadMusic()
  {
    print("Download music and play it after that.")
  }
}

class MusicService
{
  let serverService = Singleton.shared.serverService

  func playMusic()
  {
    serverService.downloadMusic()
  }
}

class Singleton
{
  static let shared = Singleton()

  let serverService = ServerService()
  let musicService = MusicService()
}


let s = Singleton.shared
print("Hello, World!")
</code></pre>

<p>We never get <code>print("Hello, World!")</code> line to be invoked.</p>