Unable to unzip "Optional.

If you encounter a fatal error error:

Unable to unzip. Optional. Some

Tracking this is not easy. What causes this error?

The code:

import UIKit class WelcomeViewController: UIViewController { let cornerRad:CGFloat = 10.0 @IBOutlet var label:UILabel @IBOutlet var lvl1:UIButton @IBOutlet var lvl2:UIButton @IBOutlet var lvl3:UIButton init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } override func viewDidLoad() { super.viewDidLoad() lvl1.layer.cornerRadius = cornerRad lvl2.layer.cornerRadius = cornerRad lvl3.layer.cornerRadius = cornerRad } } 
+8
ios swift
source share
3 answers

You get this error because you are trying to access the optional variable, which does not matter. Example:

 // This String is an optional, which is created as nil. var optional: String? var myString = optional! // Error. Optional.None optional = "Value" if optional { var myString = optional! // Safe to unwrap. } 

You can learn more about optionals in the official Swift language guide .

+8
source share

When you see this error, this is because an object, such as an unbound IBOutlet, is being accessed. The reason he says is that when accessing an optional object, most of the objects are wrapped in such a way as to resolve the value nil, and when accessing an optional object you "expand" the object to access its value, this error means that was the value assigned to the variable.

For example, in this code

 var str:String? = nil var empty = str!.isEmpty 

The str variable is declared and? means that it can be null, which makes it an optional variable, and as you can see, it is set to nil. He then creates the logical boolean variable empty and sets it to str! .IsEmpty, which matters! denotes a reversal, and since the value is nil, you will see

 Can't unwrap Optional.None error 
+1
source share

Correct your UILabel layout. your UILabel object is either bound or not. If it does not show Fatal Error.

0
source share

All Articles