Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @objc func petNotification(_ notification: Notification) {
- //Parsing
- guard let userInfo = notification.userInfo else { return }
- guard let name = userInfo["name"] as? String else { return }
- guard let type = userInfo["type"] as? String else { return }
- guard let age = userInfo["age"] as? Int else { return }
- guard let hungry = userInfo["hungry"] as? Bool else { return }
- guard let scared = userInfo["scared"] as? Bool else { return }
- //Usage of the parsed data
- print("\(type) \(name), age is \(age)")
- let hungryString = hungry ? "\(name) is hungry" : "\(name) is not hungry"
- let scaredString = scared ? "\(name) is scared" : "\(name) is not scared"
- print("\(hungryString).\(scaredString)")
- }
Add Comment
Please, Sign In to add comment