根据我对guard
swift 语句的理解,我正在执行以下操作:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let identifier = "identifier"
let dequeCell = tableView.dequeueReusableCellWithIdentifier(identifier)
guard let cell = dequeCell else
{
// The following line gives error saying: Variable declared in 'guard'condition is not usable in its body
cell = UITableViewCell(style: .Default, reuseIdentifier: identifier)
}
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
我只是想了解我们可以在guard
语句中创建一个变量并在函数的其余部分中访问它吗?还是保护语句旨在立即返回或抛出异常?
还是我完全误解了guard
语句的用法?