title: What is NSData or Data in Swift?
body: <p>I am pretty new to swift and i came across "Data" while programming in swift. i came across it while using UserDefaults in iOS. I read through the docs that Apple provided but couldn't understand much.</p>
  
  <p>Can anyone please explain to me what it is? </p>
  
  <pre><code>static var _currentUser: User?
  
      class var currentUser: User? {
          get {
              if _currentUser == nil {
                  let defaults = UserDefaults.standard
                  let savedUser = defaults.object(forKey: "savedUser") as? Data
                  if let savedUser = savedUser {
                      let dict = try! JSONSerialization.jsonObject(with: savedUser as Data, options: [])
                      _currentUser = User(currentUserInfo: dict as! NSDictionary)
                  }
              }
              return _currentUser
          }
          set(user){
              _currentUser = user
              let defaults = UserDefaults.standard
              if let user = user {
                  let data = try! JSONSerialization.data(withJSONObject: (user.userInfo)!, options: [])
                  defaults.set(data, forKey: "savedUser")
                  print("current user saved")
              }
              else {
                  defaults.removeObject(forKey: "savedUser")
              }
              defaults.synchronize()
          }
      }
  </code></pre>