Skip to content

Instantly share code, notes, and snippets.

@AfricanSwift
Last active November 26, 2015 20:45
Show Gist options
  • Save AfricanSwift/0f55017646f738311379 to your computer and use it in GitHub Desktop.
Save AfricanSwift/0f55017646f738311379 to your computer and use it in GitHub Desktop.
radex ugly option
private func handleNotificationAction(id: String?, userInfo: [NSObject: AnyObject], responseInfo: [NSObject: AnyObject]?, completion: () -> Void) {
// inline our id choices
enum idOptions: String {
case comment, invitation_accept, invitation_decline, star, complete, show, delegate, none
static var project: [idOptions] = [.invitation_accept, .invitation_decline]
static var task: [idOptions] = [.star, .complete]
}
// Unwrap optionals
let data: (id: idOptions, taskId: String, projectId: String, comment: String) = (
idOptions.init(rawValue: id ?? "") ?? .none,
userInfo["extra"]?["task_hash"] as? String ?? "",
userInfo["extra"]?["project_hash"] as? String ?? "",
responseInfo?["UIUserNotificationActionResponseTypedTextKey"] as? String ?? "")
// Fail early
guard data.id == .comment && data.comment.isEmpty ||
idOptions.project.contains(data.id) && data.projectId.isEmpty ||
idOptions.task.contains(data.id) && data.taskId.isEmpty else {
assertionFailure()
return
}
switch data.id {
case .comment:
break
case .invitation_accept:
break
case .invitation_decline:
break
case .star:
break
case .complete:
break
case .show, .delegate:
break
case .none:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment