Created
November 29, 2016 21:50
-
-
Save amlcurran/646a7d90c511346483be70387c20853e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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