Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NSUserDefaults with Xcode 8 and iOS 10

NSUserDefaults no longer appears to be a class in the iOS 10 SDK:

let defaults = NSUserDefaults.standardUserDefaults() 

This fails to compile. Was this class removed?

(This is a canonical Q&A pair to prevent the flood of duplicate questions)

like image 521
JAL Avatar asked Jun 13 '16 20:06

JAL


1 Answers

NSUserDefaults has been renamed to UserDefaults. standardUserDefaults() has been renamed to standard().

let defaults = UserDefaults.standard 

This now works.

Pre-release documentation link.

like image 75
JAL Avatar answered Nov 01 '22 19:11

JAL