9

我在 SQLite 中有一个表,我想在该表中插入数据。该表有responses_id、participant_id、answer_text、answer_option_update_date_time。response_id 和participant_id 是整数。当我将任何东西分配给参与者 ID 时,它会给出一个错误,对象不能设置为属性。

@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];  
}

当我为参与者 ID 分配一个值时,它会给出一个错误。

4

1 回答 1

39

NSInteger不是一个类,它是一个类似intor的基本类型long。在 iOSNSInteger上被typedef编辑为int,在 OS X 上被typedef编辑为long. 因此,您不应该尝试retain使用NSInteger. 您应该将您的财产声明更改为:

@property (nonatomic, assign) NSInteger participant_Id;

您的coffeeID财产也是如此。

于 2012-09-05T06:13:27.180 回答