How to declare a global int in an iPhone application

I am creating an int global variable in an iPhone application, but it gives an error.

I declare this way:

 AppDelegate.h

 int maxglobal;

When I assign this to other values, they say that the object cannot set the property in another class.

+3
source share
4 answers

Objective-C:

@property (assign) int maxglobal; // define this in app delegate

WITH

int maxglobal; // define this outside any class and it "global"
0
source

In your .h file do this

double GlobalVariable=0.0;

Make sure you do it higher @synthesizeand you're done :)

0
source

Try the following:

AppDelegate.h:
@interface AppDelegate{
    int maxglobal;
}
@property (nonatomic, readonly) int maxglobal;

AppDelegate.m
@implementation AppDelegate
@synthesize maxglobal;
0
source

you can also use the extern keyword to declare a variable as global

extern int maxglobal;
0
source

All Articles