2012-09-05 13 views
5

में एनएसआईएनटेगर संपत्ति असाइन करना मेरे पास SQLite में एक तालिका है जो मैं उस तालिका में डेटा डालना चाहता हूं। तालिका में respondes_id, participant_id, answer_text, answer_option_update_date_time है। respondes_id और participant_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]; 
} 

जब मैं सहभागी_आईडी के लिए मूल्य आवंटित कर रहा हूं तो यह एक त्रुटि देता है।

उत्तर

34

NSInteger कक्षा नहीं है, यह int या long जैसे मूल प्रकार का मूल प्रकार है। आईओएस NSIntegertypedef एड int पर ओएस एक्स पर typedef एड long पर है। इसलिए, आपको retainNSInteger पर आज़माएं नहीं।

@property (nonatomic, assign) NSInteger participant_Id; 

ही अपने coffeeID संपत्ति के लिए चला जाता है: आप करने के लिए अपनी संपत्ति घोषणा बदलना चाहिए।

+0

धन्यवाद यह मेरे लिए काम करता है –

+2

यदि आप इसे एक वस्तु होना चाहते हैं, तो आप इसे 'NSNumber' में लपेट सकते हैं। – QED

+0

कोई समस्या नहीं है। लोगों के लिए 'एनएसआईएनटेगर' और 'एनएसयूइंटर' कक्षाएं सोचने के लिए यह एक आम भ्रम है। – mttrb