title: Xcode 10 - Instance will be immediately deallocated because property is 'weak'
body: <p>I recently downloaded Xcode 10 and I noticed an apparent bug when using <code>weak</code> or <code>unowned</code> variables. I managed to create a simple example that showcases the problem so that people can recreate it. </p>
  
  <pre><code>class MainClass {
      weak var weakClass: SomeClass!
  
      init() {
  
          // WARNING: Instance will be immediately deallocated because property 'weakClass' is 'weak'
  
          self.weakClass = SomeClass()
      }
  }
  
  class SomeClass {}
  </code></pre>
  
  <p>As the error says, <code>weakClass</code> immediately deallocates once <code>MainClass</code> is initialized and is always nil. </p>
  
  <p>I have opened up the same playground with Xcode 9.3 and I can confirm that the code works fine with no errors or warnings </p>
  
  <p>Is this a bug in Xcode 10 or am I not getting something. If it is, is there any workarounds?</p>
  
  <p><strong>EDIT: Original Example</strong></p>
  
  <pre><code>class LoginCoordinator {
  
      var viewModel: LoginViewModel?
      var viewController: LoginViewController?
  
      init() {
          viewModel = LoginViewModel()
          viewModel?.coordinator = self
          viewController = LoginViewController(viewModel: viewModel!)
      }
  }
  
  
  class LoginViewModel: ViewModelDelegate {
      weak var coordinator: LoginCoordinator?
  }
  </code></pre>
  
  <p><code>coordinator</code> is always nil in <code>LoginViewModel</code></p>
  
  <p><code>AppDelegate.swift</code></p>
  
  <pre><code>@UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate {
  
      var window: UIWindow?
  
      func setupView() {
          let coordinator = LoginCoordinator()
          let navigationController = UINavigationController(rootViewController: coordinator.create)
  
          navigationController.isNavigationBarHidden = true
          navigationController.navigationBar.isTranslucent = false
  
          window = UIWindow(frame: UIScreen.main.bounds)
          window?.rootViewController = navigationController
          window?.makeKeyAndVisible()
          window?.layer.cornerRadius = 6
          window?.layer.masksToBounds = true
      }
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
          setupView()
          return true
      }
  </code></pre>