daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest May 16th, 2018 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @objc func petNotification(_ notification: Notification) {
  2.     //Parsing
  3.     guard let userInfo = notification.userInfo else { return }
  4.     guard let name = userInfo["name"] as? String else { return }
  5.     guard let type = userInfo["type"] as? String else { return }
  6.     guard let age = userInfo["age"] as? Int else { return }
  7.     guard let hungry = userInfo["hungry"] as? Bool else { return }      
  8.     guard let scared = userInfo["scared"] as? Bool else { return }
  9.     //Usage of the parsed data
  10.     print("\(type) \(name), age is \(age)")
  11.     let hungryString = hungry ? "\(name) is hungry" : "\(name) is not hungry"
  12.        
  13.     let scaredString = scared ? "\(name) is scared" : "\(name) is not scared"
  14.     print("\(hungryString).\(scaredString)")
  15. }
RAW Paste Data
Top