我的代码
·H
@interface fileHandler : NSObject
@property NSMutableArray *arrCategoryList;
@property NSMutableDictionary *dicCategoryList;
@property NSMutableDictionary *dicAllSubCategoryList;
@property NSMutableDictionary *dicProductList;
+(fileHandler *)getDataHandler;
-(void)categoryStorage:(NSMutableArray *)arrCategory :(NSMutableDictionary *)dicCategory :(NSMutableDictionary *)dicSubCategory;
的.m
static fileHandler *internalInstance=Nil;
static dispatch_once_t internalOnceToken=0;
@implementation fileHandler
-(id)init
{
self=[super init];
[self allocateMemory];
return self;
}
+(fileHandler *)getDataHandler
{
dispatch_once(&internalOnceToken,^{
internalInstance = [[fileHandler alloc] init];
if(internalInstance) {
NSLog(@"Internal instance created: %@", internalInstance);
}
});
if(internalOnceToken == -1) {
NSLog(@"Internal instance exists: %@", internalInstance);
}
return internalInstance;
}
-(void)allocateMemory
{ NSLog(@"incoming");
self.arrCategoryList=[[NSMutableArray alloc]init];
self.dicCategoryList=[[NSMutableDictionary alloc]init];
self.dicAllSubCategoryList=[[NSMutableDictionary alloc]init];
self.dicProductList=[[NSMutableDictionary alloc]init];
}
-(void)categoryStorage:(NSMutableArray *)arrCategory :(NSMutableDictionary *)dicCategory :(NSMutableDictionary *)dicSubCategory
{
// arrCategory =[[NSMutableArray alloc]init];
self.arrCategoryList=arrCategory;
// [self.arrCategoryList addObject:arrCategory];
// NSLog(@"inside data handler file==%@",self.arrCategoryList);
// dicCategory=[[NSMutableDictionary alloc]init];
self.dicCategoryList=dicCategory;
// dicSubCategory=[[NSMutableDictionary alloc]init];
self.dicAllSubCategoryList=dicSubCategory;
}
这里我创建了静态线程,然后我试图将所有值存储到其他类中提到的数组和字典中,一旦我在这里存储了值,那么我必须访问那些数据到我的app中的任何位置
可能吗?
这是对的吗? 另一个类文件 的的.m
像这样我试图将值存储在NSobject类数组中。
for(NSDictionary *DicHoleCategories in ArrCategory)
{
NSMutableDictionary *DicAllValues=[[NSMutableDictionary alloc]init];
[DicAllValues setObject:[[DicHoleCategories objectForKey:@"name"] length] !=0?[DicHoleCategories objectForKey:@"name"] :@"" forKey:@"name"];
StrName=[DicHoleCategories objectForKey:@"image"];
[DicAllValues setObject:[DicHoleCategories objectForKey:@"subcategory"] forKey:@"subcategory"];
if(StrName!=nil)
{
subimages=[NSString stringWithFormat:LocalImage"%@",StrName];
[DicAllValues setObject:subimages forKey:@"image"];
[arrImages addObject:[DicAllValues objectForKey:@"image"]];
}
[ArrName addObject:DicAllValues];
[arrSubCategory addObject:[DicAllValues objectForKey:@"subcategory"]];
[dicSubCategory setObject:[DicAllValues objectForKey:@"subcategory"] forKey:@"subcategory"];
[dicAllValues setObject:dicAllValues forKey:@"hole"];
}
[file categoryStorage:ArrCategory :dicAllValues :dicSubCategory];
输出:
Collection <__NSArrayM: 0x7f8c33c7b220> was mutated while being enumerated.'