I have an xml file that contains a structure.. In this structure, I have Actions node. So under Actions node, there are multiple “Action” nodes that each has Value and Name attributes.
e.g.
<?xml version="1.0" encoding="ISO-8859-1"?>
<Testcases SuiteName="CalculatorActions">
<Testcase id="101" Name="testAddFunction">
<Setup/>
<TearDown/>
<Test>
<Action Name="Enter first operand" Type="input" Value="5"/>
<Action Name="Enter second operand" Type="input" Value="3"/>
<Action Name="Select operator" Type="input" Value="+"/>
<Action Name="Click Calculator" Type="operation"/>
</Test>
<Validations>
<Action Name="Validate result" Type="output" Value="8"/>
</Validations>
</Testcase>
</Testcases>
What I would like to do is; I want to map these actions to the methods that I have implemented in Objective-C.
Let’s say i have a class called; “CalculatorActions” and defined 5 methods inside. I would like to map the actions that i have in xml (text format) to the methods i created in CalculatorActions.
e.g.
@interface CalculatorActions : NSObject
// Property
@property (strong, nonatomic) NSString* actionScript;
// Actions
- (void)enterFirstOperand:(double)operand;
- (void)enterSecondOperand:(double)operand;
- (void)selectOperator:(NSString*)operator;
- (void)clickCalculate;
// Validations
-(void)validateResult:(NSString*)exptectedResult;
@end
so when i read the xml file, I would want to map the actions in xml file to the corresponding method in a class.
I think what i am looking for is something like;
@interface CalculatorActions
[Action("addOperand", "Enter first operand")]
- (void) addOperand:(double)operand1 ToOther:(double)operand2;
What would be the best way to do this?
You can create an
NSInvocationinstance, set the selector, arguments, and optionally capture the return value. You can create these all with strings.e.g.
Note – the
setArgument:selector takes a pointer address, and the index of the arguments start at 2.