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

Localizing String Literals

What about the places in your application where you programmatically determine what text is displayed to the user, such as with a string literal or a Swift string interpolation? In Document.swift, you have the following line of code:

l​e​t​ ​a​l​e​r​t​ ​=​ ​N​S​A​l​e​r​t​(​)​
a​l​e​r​t​.​m​e​s​s​a​g​e​T​e​x​t​ ​=​ ​"​D​o​ ​y​o​u​ ​r​e​a​l​l​y​ ​w​a​n​t​ ​t​o​ ​r​e​m​o​v​e​ ​t​h​e​s​e​ ​p​e​o​p​l​e​?​"​
a​l​e​r​t​.​i​n​f​o​r​m​a​t​i​v​e​T​e​x​t​ ​=​ ​"​\​(​s​e​l​e​c​t​e​d​P​e​o​p​l​e​.​c​o​u​n​t​)​ ​p​e​o​p​l​e​ ​w​i​l​l​ ​b​e​ ​r​e​m​o​v​e​d​.​"​
a​l​e​r​t​.​a​d​d​B​u​t​t​o​n​W​i​t​h​T​i​t​l​e​(​"​R​e​m​o​v​e​"​)​
a​l​e​r​t​.​a​d​d​B​u​t​t​o​n​W​i​t​h​T​i​t​l​e​(​"​C​a​n​c​e​l​"​)​

That alert sheet is not ...

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