Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Option 1: if..elseif + optional unwrapping conditions
- private func handleNotificationAction(id: String?, userInfo: [NSObject: AnyObject], responseInfo: [NSObject: AnyObject]?, completion: () -> Void) {
- let taskId = userInfo["extra"]?["task_hash"] as? String
- let projectId = userInfo["extra"]?["project_hash"] as? String
- let comment = responseInfo?["UIUserNotificationActionResponseTypedTextKey"] as? String
- if id == "comment", let task = taskId, comment = comment where !comment.isEmpty {
- } else if id == "invitation_accept", let project = projectId {
- } else if id == "invitation_decline", let project = projectId {
- } else if id == "star", let task = taskId {
- } else if id == "complete", let task = taskId {
- } else if id == "show" || id == "comment" || id == "delegate", let task = taskId {
- } else {
- // assertionFailure
- }
- }
- // Option 2: switch + force unwrap
- private func handleNotificationAction(id: String?, userInfo: [NSObject: AnyObject], responseInfo: [NSObject: AnyObject]?, completion: () -> Void) {
- let taskId = userInfo["extra"]?["task_hash"] as? String
- let projectId = userInfo["extra"]?["project_hash"] as? String
- let comment = responseInfo?["UIUserNotificationActionResponseTypedTextKey"] as? String
- switch id {
- case "comment"? where taskId != nil && comment != nil && !comment.isEmpty:
- case "invitation_accept"? where projectId != nil:
- case "invitation_decline"? where projectId != nil:
- case "star"? where taskId != nil:
- case "complete"? where taskId != nil:
- case "show"?, "comment"?, "delegate"? where taskId != nil:
- default:
- // assertionFailure
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement