Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning NSInteger property in iPhone App

I have a table in SQLite I want to insert data in that table. The table has responses_id, participant_id, answer_text, answer_option_update_date_time. responses_id and participant_id are integers. When I am assigning any thing to participant_id it gives an error, object can not set to property.

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

When I am assigning a value to participant_id it gives an error.

like image 824
Nazia Jan Avatar asked Sep 05 '12 06:09

Nazia Jan


1 Answers

NSInteger is not a class, it is a basic type like an int or long. On iOS NSInteger is typedefed to an int, on OS X it is typedefed to a long. Therefore, you shouldn't try to retain an NSInteger. You should change your property declaration to:

@property (nonatomic, assign) NSInteger participant_Id;

The same goes for your coffeeID property.

like image 184
mttrb Avatar answered Nov 09 '22 03:11

mttrb