2012-05-24 26 views
3

我正在iPhone應用程序中創建全局int變量,但它會給出錯誤。如何在iPhone應用程序中聲明全局int

我聲明中這樣說:

AppDelegate.h 

int maxglobal; 

當我給你這個任何其他值好說對象不能設置爲其他類屬性。

回答

0

的Objective-C:

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

C:

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

在您的.h文件中做到這一點

double GlobalVariable=0.0;

請小心,這樣做上述@synthesize和你完成:)

+0

的問題是關於'int'不加倍! – Maulik

0

嘗試以下操作:

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

AppDelegate.m 
@implementation AppDelegate 
@synthesize maxglobal; 
0

你也可以使用extern關鍵字來聲明變量作爲全球

extern int maxglobal; 
相關問題