我在一类的以下变量中从SQL Server获取数据:
@property(retain,nonatomic) NSString* trainingName;
@property(retain,nonatomic) NSNumber* trainingCount;
在另一堂课中,我想将此值附加到NSMutableArray中,最后制作一则字典,我这样做如下:
-(void)getTrainingDetails
{
MyTestSp_GetTrainingCountsList *objReturnTrainings = [MyTestSp_GetTrainingCounts findAll];
NSMutableArray *trainingNames = [[NSMutableArray alloc]init];
NSMutableArray *trainingCounts = [[NSMutableArray alloc]init];
NSMutableDictionary *dictTrainings = [[NSMutableDictionary alloc]init];
if ([objReturnTrainings length] > 0)
{
for (MyTestSp_GetTrainingCounts *obj in objReturnTrainings)
{
// get the values and assign to NSMutable array
trainingNames = trainingName;
trainingCounts = trainingCount;
//Make the dictionary.
}
}
}
这是正确的操作方式,如何将其放入字典中?
请帮忙。
最佳答案
您似乎正在尝试将数组直接设置为数字/字符串(实际上并没有脱离obj
,因此您的代码不应编译...)。您也不需要数组来创建字典。您可以这样做:
for (MyTestSp_GetTrainingCounts *obj in objReturnTrainings)
{
dictTrainings[obj.trainingName] = obj.trainingCount;
}
关于ios - 将NSString和NSNumber附加到NSMutableArray并使NSMutabledictionary,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18180781/