2012-09-05 24 views
5

SQLite içinde bir tablo var ve bu tabloya veri eklemek istiyorum. Tabloda responses_id, participant_id, answer_text, answer_option_update_date_time var. responses_id ve participant_id tam sayıdır. Participant_id öğesine herhangi bir şey atadığımda, bir hata verir, nesne özellik olarak ayarlanamaz.iPhone Uygulamasında NSInteger özelliği atama

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

Katılımcı_adı için bir değer atarken, bir hata verir.

cevap

34

NSInteger bir sınıf değildir, temel olarak int veya long gibi temel bir türüdür. IOS'ta NSInteger, int numaralı typedef sürümlerinde, OS X üzerinde, long için typedef olarak düzenlenmiştir. Bu nedenle, retain ve NSInteger'u denememelisiniz.

@property (nonatomic, assign) NSInteger participant_Id; 

aynı senin coffeeID mülkiyet için de geçerli: Bu hizmeti kullanmak için mal beyanında değişmelidir.

+0

Teşekkürler benim için çalıştı –

+2

Eğer bir nesne olmasını istiyorsanız, onu bir 'NSNumber' içine sarın. – QED

+0

Sorun değil. İnsanların 'NSInteger' ve 'NSUInteger' sınıfları olduğunu düşünmeleri yaygın bir kafa karışıklığıdır. – mttrb

İlgili konular