如何在iPhone应用程序中声明全局int

时间:2012-05-24 05:29:18

标签: iphone objective-c xcode

我在iPhone应用程序中创建一个全局int变量,但它给出了错误。

我这样宣布:

 AppDelegate.h

 int maxglobal;

当我将此值分配给任何其他值时,它表示对象无法设置为其他类中的属性。

4 个答案:

答案 0 :(得分:0)

目标-C:

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

C:

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

答案 1 :(得分:0)

在你的.h文件中执行此操作

double GlobalVariable=0.0;

请注意上面@synthesize执行此操作并完成以下操作:)

答案 2 :(得分:0)

尝试以下方法:

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

AppDelegate.m
@implementation AppDelegate
@synthesize maxglobal;

答案 3 :(得分:0)

您还可以使用extern关键字将变量声明为全局

extern int maxglobal;