For example
< br />
< br />
What I want to do is; I want to map these operations to the methods I implemented in Objective-C.< /p>
For example, I have a class called “CalculatorActions” and define 5 methods. I want to map my actions in xml (text format) to the methods I created in CalculatorActions .
For example
@interface CalculatorActions: NSObject
// Property
@property (strong, nonatomic) NSString* actionScript;
// Actions
- (void)enterFirstOperand:(double)operand;
- (void)enterSecondOperand:(double)operand;< br />
- (void)selectOperator:(NSString*)operator;
- (void)clickCalculate;
// Validations
-(void)validateResult:(NSString*)exptectedResult;
@end
So when I read the xml file, I want to map the operation in the xml file to The corresponding method in the class.
I think what I am looking for is this;
@interface CalculatorActions
[ Action("addOperand", "Enter first operand")]
- (void) addOperand:(double)operand1 ToOther:(double)operand2;
What is the best way?
For example
SEL mySelector = NSSelectorFromString(@"testAddFunction");
Class MyClass = NSClassFromString(@"CalculatorActions");
NSString *myArgument = @"5";
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:[MyClass instanceMethodSignatureForSelector:mySelector]];
[invocation setTarget:myClass];
[invocation setSelector:mySelector];
[invocation setArgument:&myArgument atIndex:2];
[invocation invoke];
Note – setArgument: The selector accepts the pointer address, and the parameter index starts from 2.
I have an xml file containing a structure. In this structure, I have an Actions node. Therefore, Under the Actions node, there are multiple “Action” nodes, and each node has Value and Name attributes.
For example
xml version="1.0" encoding="ISO-8859-1"?>
What I want to do is; I want to map these operations to the methods I implemented in Objective-C.
For example, I have a class called “CalculatorActions” and define 5 methods. I want to map my actions in xml (text format) to the methods I created in CalculatorActions.
For example
@interface CalculatorActions: NSObject
// Property
@property (strong, nonatomic) NSString* actionScript;
< br />// Actions
- (void)enterFirstOperand:(double)operand;
- (void)enterSecondOperand:(double)operand;
- ( void)selectOperator:(NSString*)operator;
- (void)clickCa lculate;
// Validations
-(void)validateResult:(NSString*)exptectedResult;
@end
So when I read the xml file, I want to map the operations in the xml file to the corresponding methods in the class.
I think what I am looking for is this;
@interface CalculatorActions
[Action("addOperand", "Enter first operand")]
- (void) addOperand:(double)operand1 ToOther:(double )operand2;
What is the best way?
You can create NSInvocation instances, set selectors, parameters, and optionally capture the return value. You can create all of them using strings.
< /p>
For example
SEL mySelector = NSSelectorFromString(@"testAddFunction");
Class MyClass = NSClassFromString(@"CalculatorActions");
NSString *myArgument = @"5";
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:[MyClass instanceMethodSignatureForSelector:mySelector]];
[invocation setTarget:myClass];
[ invocation setSelector:mySelector];
[invocation setArgument:&myArgument atIndex:2];
[invocation invoke];
Note – setArgument: the selector accepts the pointer address, and the parameter index starts from 2 Start.