2012-09-05 10 views
5

Tengo una tabla en SQLite Quiero insertar datos en esa tabla. La tabla tiene response_id, participante_id, answer_text, answer_option_update_date_time. responses_id y participante_id son enteros. Cuando estoy asignando algo a participante_id, da un error, el objeto no puede establecerse en la propiedad.Asignar propiedad NSInteger en la aplicación iPhone

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

Cuando estoy asignando un valor a participant_id, se produce un error.

Respuesta

34

NSInteger no es una clase, es un tipo básico como int o long. En iOS NSInteger es typedef ed a int, en OS X es typedef ed a long. Por lo tanto, no debe intentar retain y NSInteger. Debe cambiar su declaración de propiedad a:

@property (nonatomic, assign) NSInteger participant_Id; 

Lo mismo ocurre con su propiedad coffeeID.

+0

gracias funcionó para mí –

+2

Si desea que sea un objeto, puede envolverlo en un 'NSNumber'. – QED

+0

No hay problema. Es una confusión común para las personas pensar que 'NSInteger' y' NSUInteger' son clases. – mttrb

Cuestiones relacionadas