Objective-C には少し慣れていないので、ご容赦ください。
まず、SQLite の管理に FMDB ライブラリを使用しています。
次のメソッドを使用して 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"]];
}
配列を適切に返しています(これを確認しました)。次に、次の方法を使用して、この 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]];
tInfo = [NSMutableString stringWithFormat:@"%@", [tInfo stringByAppendingFormat:@"%@: %@\n", type, effectivenessString]];
}
次の 2 つのメソッドを呼び出します。
-(NSMutableString *)getEffectivenessString:(NSNumber *) numberPassedIn
{
double dFactor = [numberPassedIn doubleValue];
//adds the above value to a string, this will not affect anything
}
と
-(NSNumber *) listProduct: (NSMutableArray *)listOfValues //calculates the product of an NSMutableArray of numbers
{
NSNumber *product=[NSNumber numberWithDouble:1.0];
for(int i = 0; i < [listOfValues count]; i++)
{
NSNumber *newVal = [listOfValues objectAtIndex:i];
product = [NSNumber numberWithDouble:[product doubleValue] * [newVal doubleValue]];
}
return product;
}
したがって、これらのメソッドを呼び出すと、次のエラーが発生します。
2013-08-04 13:52:04.514 effectCalculator[45573:c07] -[__NSArrayM doubleValue]:
unrecognized selector sent to instance 0x8c19e00
2013-08-04 13:52:04.521 effectCalculator[45573:c07] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSArrayM doubleValue]: unrecognized
selector sent to instance 0x8c19e00'
重要な注意事項: このエラーは、NSMutableDictionary の入力ではなく、取得時に発生します。これは、このディクショナリの人口が問題ではないことを意味しますが、データの取得に問題がある理由と関係がある可能性があります。
では、このエラーの原因は何でしょうか?