initialization - The correct way to override an initializer in Swift 1.1 -


itemprop = "text">

It used to work in Xcode 6.1 Beta:

  class MainViewController: NSViewController {feature override Init () {self.init (nibName: "MainView", bundle: nil)}} I do not compile it after switching to 6.1 GM2. It seems that this issue has been introduced in Swift 1.1. I have tried  feature override init? () ,  feature init? ()  and  override init? () , neither worked.  

So what is the correct way to override such starters today?

is trying to implement init () a non -Functional initial init? (NibName: bundle :) , which is a fuses introduction does not work: If the super.init call fails, you leave it with a non-preliminary example Will not allow Swift.

Or is it another way, the result of using a Fizla Starter is an alternative, and you can not use a non-alternative value instead of alternative options. And in the case of Class Initialization and Inheritance, you can not change the option of a non-optional self option. You can only set up the status of self in a different initializer.

Instead, you can remove option / failure with short song and dance: <> Code> class MainViewController pre: NSViewController {Override init (nibName nibNameOrNil: string ?, bundle) nibBundleOrNil: NSBundle) {super.init (nibName: nibNameOrNil, bundle: nibBundleOrNil) here check the state and provide // application-specific diagnosis if this is incorrect} feature override init () {self.init (nibName: "MainView" , Bundle: zero)} // need this, too, or the compiler complains that it is missing the init necessary (coder: NSCoder)? {FatalError ("not implemented") // ... or actual execution}}

a init! initializer produces an unbound unwrapped alternative (IUO) one ?? ?? As an IUO type can be used to bridge the code that works with optional and non-optional values, a init! initializer Fusible and non-you can not delegate Fusion Starters to a non-filing initiator, but you can not get a init! initializer and init! From to a fuzzy launcher initiator

Here, NSViewController is the beginner you want to use, is completely fuzzy so you can call it init! Override with Starter. Then, you can declare a non-fusible feature int that your new init! Representative of initializer


We often avoid IUo, and in detail init! initializers, because we generally want to expressly express or disallow it for clearly or failure. However, one of the most common general usage cases for IUO and their relatives is to turn on conditions that guarantee that only your source code can guarantee that your code behaves accurately. IBOutlet s is the best example of this ???? You guarantee the status of your IBOutlet variable in your Nib / Storyboard, but the compiler does not know about that? As there is something else to do with bundled resources

This small delegation dances into your code the burden of failure at a specific, easily debugable place. If your app fails from init () to super.init (nibName: bundle :) , your app will crash but you can expect that the call is only too Expect to fail in specific (and most development-time) situations.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -