0

我正在从 SQL 服务器获取数据,其中包含一个类中的以下变量:

@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.
    }

}

}

这是正确的做法吗?我怎样才能把它放在字典里?

请帮忙。

4

1 回答 1

2

您似乎正在尝试将您的数组直接设置为您的数字/字符串(您实际上并没有退出,obj因此您的代码不应该编译......)。您也不需要数组来创建字典。你可以这样做:

for (MyTestSp_GetTrainingCounts *obj in objReturnTrainings)
{
    dictTrainings[obj.trainingName] = obj.trainingCount;
}
于 2013-08-12T06:36:34.723 回答