O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing the Preferences to User Defaults

Now, add setters for the activeVoice and activeText properties. You will use each setter to store the user’s preferred value for that preference.

 ​ ​ ​ ​v​a​r​ ​a​c​t​i​v​e​V​o​i​c​e​:​ ​S​t​r​i​n​g​?​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​s​e​t​ ​(​n​e​w​A​c​t​i​v​e​V​o​i​c​e​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​u​s​e​r​D​e​f​a​u​l​t​s​.​s​e​t​O​b​j​e​c​t​(​n​e​w​A​c​t​i​v​e​V​o​i​c​e​,​ ​f​o​r​K​e​y​:​ ​a​c​t​i​v​e​V​o​i​c​e​K​e​y​)​
 ​ ​ ​ ​ ​ ​ ​ ​}​ ​ ​ ​ ​ ​ ​ ​ ​g​e​t​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​r​e​t​u​r​n​ ​u​s​e​r​D​e​f​a​u​l​t​s​.​o​b​j​e​c​t​F​o​r​K​e​y​(​a​c​t​i​v​e​V​o​i​c​e​K​e​y​)​ ​a​s​?​ ​S​t​r​i​n​g​ ​ ​ ​ ​ ​ ​ ​ ​}​ ​ ​ ​ ​}​ ​ ​ ​ ​v​a​r​ ​a​c​t​i​v​e​T​e​x​t​:​ ​S​t​r​i​n​g​?​ ​{​ ​ ​ ​ ​ ​ ​ ​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required