Objective c doubleValue上的选择器无效

Objective c doubleValue上的选择器无效,objective-c,Objective C,对Objective-C有点陌生,所以请容忍我 首先,我使用FMDB库进行SQLite管理 我正在使用以下方法填充NSMutableDictionary: //.... while([effectivenessResults next]) //this loops through the results of a query (verified that this works) { NSMutableArray *dFactors = [[NSMutableArray a

对Objective-C有点陌生,所以请容忍我

首先,我使用FMDB库进行SQLite管理

我正在使用以下方法填充NSMutableDictionary:

//....
while([effectivenessResults next]) //this loops through the results of a query (verified that this works)
    {
        NSMutableArray *dFactors = [[NSMutableArray alloc]init];
        if([resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]])
        {
            dFactors = [resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]];
        }
        NSNumber *effectivenessValToAdd = [NSNumber numberWithDouble:[effectivenessResults doubleForColumn:@"dFactor"]/100];
        [dFactors addObject:[NSMutableString stringWithFormat:@"%@",effectivenessValToAdd]];
        [resultDict setObject:dFactors forKey:[effectivenessResults stringForColumn:@"tName"]];
    }
for(id type in tEffect) //tEffect is the NSMutableDictionary, returned from the previous code (there known as resultDict)
{
    effectivenessString = [self getEffectivenessString:[tEffect objectForKey:type]];

    tInfo = [NSMutableString stringWithFormat:@"%@", [tInfo stringByAppendingFormat:@"%@: %@\n", type, effectivenessString]];

}
我正在正确返回数组(我已经验证了这一点)。然后,我在别处使用以下方法访问此NSMutableDictionary:

//....
while([effectivenessResults next]) //this loops through the results of a query (verified that this works)
    {
        NSMutableArray *dFactors = [[NSMutableArray alloc]init];
        if([resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]])
        {
            dFactors = [resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]];
        }
        NSNumber *effectivenessValToAdd = [NSNumber numberWithDouble:[effectivenessResults doubleForColumn:@"dFactor"]/100];
        [dFactors addObject:[NSMutableString stringWithFormat:@"%@",effectivenessValToAdd]];
        [resultDict setObject:dFactors forKey:[effectivenessResults stringForColumn:@"tName"]];
    }
for(id type in tEffect) //tEffect is the NSMutableDictionary, returned from the previous code (there known as resultDict)
{
    effectivenessString = [self getEffectivenessString:[tEffect objectForKey:type]];

    tInfo = [NSMutableString stringWithFormat:@"%@", [tInfo stringByAppendingFormat:@"%@: %@\n", type, effectivenessString]];

}
它调用以下两种方法:

-(NSMutableString *)getEffectivenessString:(NSNumber *) numberPassedIn
{
    double dFactor = [numberPassedIn doubleValue];
    //adds the above value to a string, this will not affect anything
}

重要注意事项:此错误发生在检索时,而不是在填充NSMutableDictionary时。这意味着这本词典的数量不是问题,但可能与检索数据时遇到问题有关


那么是什么导致了这个错误呢?

您的代码很难理解。以后请发布一个编译过的最小样本,或者至少是一个可理解的代码块

话虽如此,我相信你的问题在于这一点:

for(id type in tEffect) //tEffect is the NSMutableDictionary, returned from the previous code (there known as resultDict)
{
    effectivenessString = [self getEffectivenessString:[tEffect objectForKey:type]];
resultdct
包含什么

[resultDict setObject:dFactors ...
但是
dfacts
是一个
NSMutableArray
。Well
getEffectivenessString
需要一个
NSNumber
,而不是
NSMutableArray
。它抱怨道。此外,我认为您打算让该方法采用字符串,而不是数字,尽管我不明白为什么在加载它们时(而不是在使用它们时)不进行强制转换


由于Objective C不支持强类型数组或字典,因此将来最好的防御方法是更合理地命名变量。当你试图调用一个需要一个带数组的数字的方法时,它应该很突出。

我好像忘记调用我在问题中提供的
listProduct
方法了。这是一个非常愚蠢的疏忽。另外,为了提供一个易于阅读的问题,我试图缩短代码,但这可能会使您更难理解。非常感谢。