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

Create Names for the Defaults

You will be registering factory defaults, writing user preferences for defaults, and reading values for defaults, all based on a string that names each default. You will define a constant string for each of the default names.

At the top of PreferenceManager.swift, above the PreferenceManager, add the following constants:

i​m​p​o​r​t​ ​F​o​u​n​d​a​t​i​o​n​

p​r​i​v​a​t​e​ ​l​e​t​ ​a​c​t​i​v​e​V​o​i​c​e​K​e​y​ ​=​ ​"​a​c​t​i​v​e​V​o​i​c​e​"p​r​i​v​a​t​e​ ​l​e​t​ ​a​c​t​i​v​e​T​e​x​t​K​e​y​ ​=​ ​"​a​c​t​i​v​e​T​e​x​t​"​

c​l​a​s​s​ ​P​r​e​f​e​r​e​n​c​e​M​a​n​a​g​e​r​ ​{​

Why define constants that simply contain a fixed string? After all, you could just remember what the string was and type it in whenever ...

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