Global variables

Instead of using #define, Objective-C programmers commonly use global variables to hold constant values.

Let’s add to your program to explain. First, there is a class named NSLocale that stores information about different geographical locations. You can get an instance of the user’s current locale and then ask it questions. For instance, if you wanted to know what the currency is in the user’s locale, you could ask for it like this:

#​i​m​p​o​r​t​ ​<​F​o​u​n​d​a​t​i​o​n​/​F​o​u​n​d​a​t​i​o​n​.​h​>​ i​n​t​ ​m​a​i​n​ ​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​ {​ ​ ​ ​ ​@​a​u​t​o​r​e​l​e​a​s​e​p​o​o​l​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​N​S​L​o​g​(​@​"​\​u​0​3​c​0​ ​i​s​ ​%​f​"​,​ ​M​_​P​I​)​;​ ​ ​ ​ ​ ​ ​ ​ ​N​S​L​o​g​(​@​"​%​d​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.