// MyClass.h
@interface MyClass : NSObject
{
NSDictionary *dictobj;
}
@end
//MyClass.m
@implementation MyClass
-(void)applicationDiDFinishlaunching:(UIApplication *)application
{
}
-(void)methodA
{
// Here i need to add objects into the dictionary
}
-(void)methodB
{
//here i need to retrive the key and objects of Dictionary into array
}
我的问题是,因为两个和了methodA的methodB正在使用的NSDictionary对象[即dictobj]在该方法中,我应该写这样的代码:如何在Objective-C中声明一个全局变量?
dictobj = [[NSDictionary alloc]init];
在两种方法我不能做两遍,因此如何在全球范围内做到这一点?
这不是一个全局变量。这是一个实例变量。全局变量只存在于整个应用程序的一个位置。一个实例变量存在于其包含的类的每个实例中。 –
你是对的.... – suse