I am confused as to how to unwrap an optional value. I am checking to see if my variable has any nil values and i still get an error. I am trying to perform this logic inside of an NSCollectionViewItem. Is it not possible in there? I keep getting this error no matter what I do:
fatal error: unexpectedly found nil while unwrapping an Optional value
import Cocoa
class ImageCollectionView_Item: NSCollectionViewItem {
@IBOutlet weak var label: NSTextField!
var test: String?
override func viewDidLoad() {
super.viewDidLoad()
if test != nil {
print("success")
label.stringValue = "success"
} else {
print("fail")
label.stringValue = "fail"
}
}
}