-1

Possible Duplicate:
How to use global variables in Objective-C?

I want to know how can i define global variable in Objective-c?

Community
  • 1
  • 1
user930195
  • 432
  • 1
  • 5
  • 19

4 Answers4

0

You might want to check the definition of singleton.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
Sergey Lost
  • 2,511
  • 3
  • 19
  • 22
  • This is the best approach to attack this problem.Here's a link explaining what a singleton is http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Singleton.html – El Developer Oct 24 '11 at 12:01
0

You can use app-delegate or create shared instance of a class.

sach
  • 1,069
  • 4
  • 15
  • 29
0

There are two approaches:

  1. App delegate
  2. Singleton

(Well, actually 2.5, since simply using a static variable is a more primitive version of singleton.)

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
-1

You should create a header file like

  // Constants.h
    extern NSString * const Constant1;
    extern NSString * const Constant2;

You can include this file in each file that uses the constants or in the pre-compiled header for the project.

You define these constants in a .m file like

// Constants.m
NSString * const Constant1 = @"FirstConstant";
NSString * const Constant2 = @"SecondConstant";
aahsanali
  • 3,537
  • 23
  • 21