2012-09-05 5 views
5

私はSQLiteにテーブルを持っています。そのテーブルにデータを挿入したいのですが。表にはrespond_id、participant_id、answer_text、answer_option_update_date_timeがあります。 respond_idとparticipant_idは整数です。 participant_idに何かを割り当てているときにエラーが発生すると、オブジェクトはプロパティに設定できません。iPhone AppでNSIntegerプロパティを割り当てる

@interface Coffee : NSObject { 

NSInteger coffeeID; 
NSInteger participant_Id; 

NSString*question_Id; 
NSString*answer_option; 
NSString*answer_text; 
NSString*update_date_time; 




//Intrnal variables to keep track of the state of the object. 
} 

@property (nonatomic, readonly) NSInteger coffeeID; 
@property (nonatomic, retain) NSInteger participant_Id; 

@property (nonatomic, copy) NSString *question_Id; 
@property (nonatomic, copy) NSString *answer_option; 
@property (nonatomic, copy) NSString *answer_text; 
@property (nonatomic, copy) NSString *update_date_time; 


- (void)save_Local { 
    CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate]; 

    Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:0]; 

    coffeeObj.participant_Id=mynumber; 

    NSString*question="1"; 
    coffeeObj.question_Id=question; 
    coffeeObj.answer_option=selectionAnswerOption; 
    coffeeObj.answer_text=professionTextField.text; 




    NSDate* date = [NSDate date]; 
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"]; 
    NSString* str = [formatter stringFromDate:date]; 

    UPDATE_DATE_TIME=str; 


    coffeeObj.update_date_time=UPDATE_DATE_TIME; 

    //Add the object 
    [appDelegate addCoffee:coffeeObj]; 
} 

participant_idに値を割り当てるときにエラーが発生します。

答えて

34

NSIntegerはクラスではなく、intまたはlongのような基本型です。 iOS NSIntegerは、inttypedefであり、OS Xでは、がlongになっています。したがって、retainにはNSIntegerを入力しないでください。

@property (nonatomic, assign) NSInteger participant_Id; 

同じことがあなたのcoffeeID財産のために行く:あなたはにあなたの財産の宣言を変更する必要があります。

+0

ありがとう、それは私のために働いた –

+2

オブジェクトにしたい場合は、それを 'NSNumber'でラップすることができます。 – QED

+0

問題ありません。人々が 'NSInteger'と' NSUInteger'がクラスであると考えるのはよくある混乱です。 – mttrb

関連する問題