title: Conversion of custom init routines in Swift
body: <p>I need to subclass SVModalWebViewController.m (<a href="https://github.com/samvermette/SVWebViewController" rel="nofollow">GitHub</a>), which is itself a subclass of <code>UINavigationController</code>, and am incorporating this code into a new app that will be created entirely in Swift.  I've run into several issues, so I decided to first convert just this very simple class into Swift to debug.</p>
  
  <p>Initialization is a little different in Swift compared with Objective-C (<a href="https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/Initialization.html" rel="nofollow">read more about Swift initialization here</a>), which is why I'm not returning <code>self</code> in the Swift code.</p>
  
  <p>Here's the original Obj-C code (minus the *.h, which instantiates <code>barsTintColor</code>):</p>
  
  <pre><code>#import "SVModalWebViewController.h"
  #import "SVWebViewController.h"
  
  @interface SVModalWebViewController ()
  
  @property (nonatomic, strong) SVWebViewController *webViewController;
  
  @end
  
  
  @implementation SVModalWebViewController
  
  #pragma mark - Initialization
  
  
  - (id)initWithAddress:(NSString*)urlString {
      return [self initWithURL:[NSURL URLWithString:urlString]];
  }
  
  - (id)initWithURL:(NSURL *)URL {
      self.webViewController = [[SVWebViewController alloc] initWithURL:URL];
      if (self = [super initWithRootViewController:self.webViewController]) {
          UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                                      target:self.webViewController
                                                                                      action:@selector(doneButtonClicked:)];
  
          if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
              self.webViewController.navigationItem.leftBarButtonItem = doneButton;
          else
              self.webViewController.navigationItem.rightBarButtonItem = doneButton;
      }
      return self;
  }
  
  - (void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:NO];
  
      self.webViewController.title = self.title;
      self.navigationBar.tintColor = self.barsTintColor;
  }
  
  @end
  </code></pre>
  
  <p>And here's the entire Swift version of the class (I simplified to just one init method since I didn't need to init with URL specifically):</p>
  
  <pre><code>import UIKit
  
  class SVModalWebViewController: UINavigationController {
      var webViewController: SVWebViewController!
      var barsTintColor: UIColor?
  
      // This was added because of a compiler error indicating it needed to be added
      init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
          super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
      }
  
      init(address urlString: String!) {
          let url: NSURL = NSURL.URLWithString(urlString)
          self.webViewController = SVWebViewController(URL: url)
          super.init(rootViewController: self.webViewController)
  
          let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self.webViewController, action: Selector("doneButtonClicked:"))
  
          if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
              self.navigationItem.leftBarButtonItem = doneButton
          } else {
              self.navigationItem.rightBarButtonItem = doneButton
          }
      }
  
      override func viewWillAppear(animated: Bool) {
          super.viewWillAppear(animated)
  
          // self.title may not be set, and is considered an optional in Swift, so we have to check first
          if self.title {self.webViewController.title = self.title}
          self.navigationBar.tintColor = self.barsTintColor
      }
  }
  </code></pre>
  
  <p>The issue I'm having relates to setting the <code>Done</code> button in the <code>navigationItem</code>.  Currently they're not showing up at all when this code is called:</p>
  
  <pre><code>let webViewController = SVModalWebViewController(address: "http://www.google.com");
  webViewController.barsTintColor = UIColor.blueColor()
  self.presentModalViewController(webViewController, animated: true)
  </code></pre>
  
  <p>The modal view appears just fine and I'm able to correctly set the bar color property, but the <code>Done</code> button does not show up.  It appears that I don't have proper access to the <code>navigationItem</code> of the <code>UINavigationController</code>.  Note that I had to add the init with nibName method due to a compiler error without it.  This wasn't required in the Obj-C code and I'll admit I'm not sure why it's needed in Swift - that could be part of the issue. </p>
  
  <p>Any thoughts as to why I cannot set the <code>self.navigationItem.leftBarButtonItem</code> property of the <code>UINavigationController</code>?  Thanks!</p>