数字 (1、2、3、4 など)、演算 (+、-、/、* など)、および変数 ( x、y、z など)。変数と関連する値を NSDictionary に格納しています。キーは、NSNumber 値がそれぞれ 5,5,2 の x、y、z に等しい NSString です。NSArray の変数を、NSDictionary に格納されている実際の値に置き換えたいと考えています。オブジェクトを置き換えようとすると、次のエラーが発生し続けます。助けてください。
-[__NSArrayI replaceObjectAtIndex:withObject:]: 認識されないセレクターがインスタンスに送信されました
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithDouble:5],@"x",
[NSNumber numberWithDouble:5],@"y",
[NSNumber numberWithDouble:2],@"z",
nil];
+ (double)runProgram:(id)program
usingVariableValues:(NSDictionary *)variableValues;
{
// introspection - ensure program is NSArray and variableValues is NSDictionary
if ([program isKindOfClass:[NSArray class]] && [variableValues isKindOfClass: [NSDictionary class]])
{
// array for program stack
NSMutableArray *stack = [program copy];
// Loop to replace variables with actual values in NSDictionary
for (NSUInteger i = 0; i < [stack count]; i++)
{
NSLog(@"object at index = %@", [stack objectAtIndex:i]);
if ([[stack objectAtIndex:i] isKindOfClass:[NSString class]] && [[stack objectAtIndex:i] isEqualToString: @"x"])
{
// replace variable with value in corresponding value in dictionary
NSNumber *numberKeyValue = [variableValues objectForKey:@"x"];
[stack replaceObjectAtIndex:i withObject:numberKeyValue];
}
}
return 0
}