我遇到了Swift在访问我的变量yLabelMax时崩溃的问题。它崩溃了以下信息:
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file.",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#F44336",
confirmButtonText: "Yes, Sure !",
closeOnConfirm: true
}, function () {
swal({
title: "Message",
text: 'Imaginary file deleted.',
type: "success"
}); });
我添加了一些检查以查看以下代码发生了什么:
fatal error: unexpectedly found nil while unwrapping an Optional value
当我运行此代码时,控制台会打印:
if (yValueMax != nil){
print ("value is \(yValueMax)")
}
else{
print (" is nil")
}
所以看起来代码正在运行if和else语句。变量如何既可以是nil又可以同时包含一个值?
答案 0 :(得分:2)