0

我需要一些关于创建自定义类和方法的建议。我想创建一个自定义类来进行计算。该类应该提供一个可以在 ViewController 类中调用的方法。在 ViewController 中,一个参数(例如一个数组)被传递给自定义类方法,并返回一个计算值,设置一个 ViewController 变量,如下所示:

//called in ViewController.m
viewControllerObject   = [CustomClass customClassMethod:passedArray];

我需要知道什么才能意识到这一点?这是一种可以接受的方法吗?

EDTI:我的第一次尝试(不要笑):

#import <Foundation/Foundation.h>

@interface ShapiroWilk : NSObject

@property (nonatomic, retain) NSNumber *pValue;

+ (id) SW_pValue:(NSNumber *)apValue;

@end

-h 文件:

#import "ShapiroWilk.h"

@implementation ShapiroWilk

@synthesize pValue;

+ (id) SW_pValue:(NSNumber *)apValue
{
    ShapiroWilk *pValue = [[self alloc] init];

    pValue.pValue = apValue;

    //how would I calculate and return values to the calling controller?

    return pValue;
}

@end
4

0 回答 0