Skip to content

Instantly share code, notes, and snippets.

@donnywals
Created February 8, 2016 18:45
Show Gist options
  • Save donnywals/010aa0c1c917fcdb6895 to your computer and use it in GitHub Desktop.
Save donnywals/010aa0c1c917fcdb6895 to your computer and use it in GitHub Desktop.
enum BSCellIdentifier: String {
case ActiveGoalBased = "activeGoalbased"
case ActiveTimeBased = "activeTimeBased"
case ActiveWaiting = "activeWaiting"
case Past = "past"
static func identifierForChallenge(challenge: Challenge, inSection section: Int, withType type: SelectionType) -> String {
if type == .Active {
if section == 0 {
if challenge.challengeType.isGoalBased() {
return self.ActiveGoalBased.rawValue
} else if challenge.challengeType.isTimeBased() {
return self.ActiveTimeBased.rawValue
}
} else {
return self.ActiveWaiting.rawValue
}
} else if type == .Available {
if section == 0 {
return self.ActiveWaiting.rawValue
} else {
return self.ActiveGoalBased.rawValue
}
} else {
return self.Past.rawValue
}
}
}
protocol WaitingCellDelegate {}
protocol ChallengeUserCell {
var challengeUser: String { get set }
}
protocol ConfigurableUserCell {
func configureWithChallenge(challenge: Challenge)
func configureWithChallenge(challenge: Challenge, hasAccepted: Bool)
}
protocol WaitingCell {
var delegate: WaitingCellDelegate { get set }
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// let challenge = challenges[indexPath.section][indexPath.row]
let tableCellIdentifier: String = BSCellIdentifier.identifierForChallenge(challenge, inSection: indexPath.section, withType: selectedType)
guard let cell = tableView.dequeueReusableCellWithIdentifier(tableCellIdentifier) else {
return UITableViewCell()
}
cell.selectionStyle = .None
if let challengeCell = cell as? ChallengeUserCell {
challengeCell.challengeUser = challengeUser.username == loggedInUser.username ? loggedInUser : challengeUser
}
if let configureCell = cell as? ConfigurableUserCell {
if selectedType == .Active && indexPath.section == 0 {
configureCell.configureWithChallenge(challenge)
} else if selectedType == .Active && indexPath.section == 1 {
configureCell.configureWithChallenge(challenge, hasAccepted: true)
} else if selectedType == .Available && indexPath.section == 0 {
configureCell.configureWithChallenge(challenge, hasAccepted: false)
} else if selectedType == .Available && indexPath.section == 1 {
configureCell.configureWithChallenge(challenge)
} else if selectedType == .Past {
configureCell.configureWithChallenge(challenge)
}
}
if let waitingCell = cell as? WaitingCell {
waitingCell.delegate = self
}
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment