@interface Set : NSObject
{
// instance variables
int repetitions;
int weight;
}
// functions
- (id)init;
- (id)initWithReps: (int)newRepetitions andWeight: (int)newWeight;
@implementation Set
-(id)init
{
if (self = [super init]) {
repetitions = 0;
weight = 0;
}
return self;
}
-(id)initWithReps: (int)newRepetitions andWeight: (int)newWeight
{
if (self = [super init])
{
repetitions = newRepetitions;
weight = newWeight;
}
return self;
}
@implementation eFit2Tests
- (void)setUp
{
[super setUp];
// Set-up code here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void)testInitWithParam
{
Set* test = nil;
test = [test initWithReps:10 andWeight:100];
NSLog(@"Num Reps: %d", [test reps]);
if([test reps] != 10) {
STFail(@"Reps not currectly initialized. (initWithParam)");
}
NSLog(@"Weight: %d", [test weight]);
if([test weight] != 100) {
STFail(@"Weight not currectly initialized. (initWithParam)");
}
}
初始化出於某種原因,因爲重複和重量的值總是等於0,在此代碼段底部的測試失敗我來自一個背景在Java和我無言以對至於爲什麼是這樣。很抱歉的愚蠢的問題...Objective-C的初始化函數沒有正確
非常感謝! –