-4

您好,我想知道如何使用此方法中的变量

+ (NSString *) yourCalculation:(NSString *)height:(NSString *)weight{
    double bmiVal = 0;
     if (weight > 0 && height > 0) {
         CGFloat wInPounds = [weight floatValue];
         CGFloat hInInches = [height floatValue];
         CGFloat hInCms = hInInches *0.393700787;
    }
}

在这个方法中

 +(NSString *) actualCalculation{
       float val = wInPounds/(hInCms*hInCms);
       float bmiVal = val *703;
 }

这只是代码的一小部分,但它涵盖了我想要用它做的事情。

如果有人能告诉我如何做到这一点,我将不胜感激。

感谢您

4

1 回答 1

1

创建一个自定义类,该类具有您要共享的各种值的属性并返回其实例。例如,假设一个MyNumerics具有明显属性的类:

+ (MyNumerics *) yourCalculation:(NSString *)height weight:(NSString *)weight {
    MyNumerics *result = nil;
    double bmiVal = 0;
    if (weight > 0 && height > 0) {
        result = [[MyNumerics alloc] init];
        result.wInPounds = [weight floatValue];
        result.hInInches = [height floatValue];
        result.hInCms = hInInches *0.393700787;
    }
    return result;
}

让调用例程在其计算中使用结果的属性。

于 2012-11-17T15:55:35.767 回答