2011-08-07 4 views
0

제품 빌드가 성공했지만 테스트가 실패합니다. 아래에 STAssertEquals 행에보고 된 유형 불일치 오류를 어떻게 전달합니까?Xcode : Objective-C : 형식이 일치하지 않습니다.

STAssertEquals((TransactionType)transaction.type, TransactionTypePay, @"type property works"); 

하지만, 왜 내가해야 :

// TransactionSpec.m 

#import "Transaction.h" 

@interface TransactionSpec : SenTestCase 
@end 

@implementation TransactionSpec 

#pragma mark Properties 

- (void)testProperties { 
    Transaction *transaction = [[Transaction alloc] init]; 
    transaction.type = TransactionTypePay; 

    STAssertNotNil(transaction, @"transaction exists"); 
    STAssertEquals(transaction.type, TransactionTypePay, @"type property works"); // Type mismatch 
} 

@end 

// Transaction.h 

typedef enum { 
    TransactionTypePay, 
    TransactionTypeCharge 
} TransactionType; 

@interface Transaction : NSObject 

@property (nonatomic) TransactionType *type; 

@end 

// Transaction.m 

#import "Transaction.h" 

@implementation Transaction 

@synthesize type; 

@end 

답변

2

귀하의 type 속성은 아마 그래서

+0

어떻게 선언해야합니까? 난 그냥 [''] (https://github.com/enormego/UIKit/blob/af0df999735b29259b2a64342d616bc04bce54de/UITableView.h#L15-18). – ma11hew28

+0

오! 알았다! 감사! – ma11hew28

1

transaction.typeTransactionType에 대한 수정 문제를 주조 안이 열거 형하는 포인터로 선언 선언 할 때부터해야합니다.

@property (nonatomic) TransactionType *type; 
+0

죄송합니다. 'type' 전에 별표 (*)를 꺼내십시오. 그렇다면 캐스팅하지 않아도됩니다. – ma11hew28

3

귀하의 type 속성은 TransactionTypePay 실제 TransactionType 동안 (아마 것은 아니다)을 TransactionType포인터입니다.

+0

달콤한! 이제 전달됩니다. 감사. 어리석은 오류. :) – ma11hew28

관련 문제