我是 Xcode 的新手,我正在尝试用数组和字典创建一个类。我不明白如何正确初始化对象。我究竟做错了什么?
“主数据.h”
#import <Foundation/Foundation.h>
@interface maindata : NSDictionary
{
NSDictionary *maindict;
NSArray *arrayofallmethods;
NSArray *categories;
NSArray *methods;
}
@property(nonatomic,retain) NSDictionary *maindict;
@property(nonatomic,retain) NSArray *categories;
@property(nonatomic,retain) NSArray *methods;
@property(nonatomic,retain) NSString *pathtoplist;
+(maindata *) shareddata;
@end
“主数据.m”
#import "maindata.h"
@implementation maindata
@synthesize maindict;
@synthesize methods;
@synthesize categories;
@synthesize pathtoplist;
static maindata *shareddata_;
-(id)init
{
if(self == [super init])
{
pathtoplist = [[NSBundle mainBundle] pathForResource:@"allData" ofType:@"plist"];
shareddata_.maindict = [NSMutableDictionary dictionaryWithContentsOfFile:pathtoplist];
shareddata_.methods = [maindict allValues];
}
return shareddata_;
}
+(maindata *) shareddata
{
if (!shareddata_)
{
shareddata_ = [[maindata alloc] init];
}
return shareddata_;
}
@end