2012-08-23 59 views
-2

我想在我的ViewController中聲明一個NSInteger變量,但出現錯誤。類型或屬性(NSUInteger(又名無符號整數))與伊娃(int)的類型不匹配

在我ViewController.h我有

@interface MainViewController : UIViewController{ 
    NSInteger currentSection; 
    //Other stuff 
    } 

    @property (assign,nonatomic) NSUInteger currentSection; 
@end 

,在我ViewController.m我:

@implementation MainViewController 

//Other stuff 
@synthesize currentSection; 

但我得到這個錯誤:

Type of property 'currentSection' ('NSUinteger' (aka 'unsigned int')) does not match type of ivar 'currentSection' ('int')

爲什麼我用一條簡單的指令得到這個錯誤?
我正在使用Xcode 4.4和ARC。

+0

再次閱讀錯誤消息。或者也許是第一次。 –

回答

1

您正在要求編譯器合成一個NSUInteger屬性和一個NSInteger伊娃。你必須決定什麼類型的財產應該是,並相應地適應伊娃的類型。

請注意,無符號整數不等於(隱式帶符號)整數。將一個投射到另一個可能會給你意想不到的結果。

+0

我很愚蠢,我沒有看到那個錯誤!非常感謝你 – user1600801

相關問題