Skip to content

Instantly share code, notes, and snippets.

@amlcurran
Created November 29, 2016 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amlcurran/646a7d90c511346483be70387c20853e to your computer and use it in GitHub Desktop.
Save amlcurran/646a7d90c511346483be70387c20853e to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if recipes[indexPath.row].isPromoted {
let promotedCell = tableView.dequeueReusableCell(withIdentifier: "promoted", for: indexPath) as! PromotedRecipeCell
promotedCell.recipe = recipe
promotedCell.promotion = recipe.promotion // we've guarded here using the isPromoted method, so the value is unwrapped
return promotedCell
} else {
let normalCell = tableView.dequeueReusableCell(withIdentifier: "normal", for: indexPath) as! RecipeCell
normalCell.recipe = recipe
return normalCell
}
}
extension Recipe {
var isPromoted: Bool (guards promotion)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment