guard
迅速なステートメントの理解に応じて、次のことを行っています。
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
または、ステートメントの使用法を完全に誤解していますか?