NSUserDefaults in Swift and Objective C iOS

Our today’s topic is NSUserDefaults in Swift and Objective C iOS.

NSUserDefaults is the easiest way to save any data into your app, today we will learn how to save and fetch data in your app using NSUserDefaults in Swift and Objective C. It has some limitations but very simple to implement. And you must check Apple’s Documentation on NSUserDefaults.

In Swift you can save data of type

  • NSData
  • String
  • NSDate
  • Array
  • Dictionary
  • Bool
  •  NSNumber
    • UInt
    • Int
    • Float
    • Double

Let save some data in our app.

In Swift


Above we are saving data into 2 keys “title” & “description”,  defaults.synchronize(), is used to save data or update data for those keys. For different types of data check below.

NSUserDefaults Swift

Now fetching data from NSUserDafaults.


In Objective – C

Saving data in NSUserDefaults


Fetching data from NSUSerDefaults.



Today we learn how to use NSUserDefaults in Swift and Objective C iOS. You can also request for topics. Thanks.

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.