在iPhone App中分配NSInteger属性
发布时间:2020-12-14 19:53:03 所属栏目:百科 来源:网络整理
导读:我在SQLite中有一个表我想在该表中插入数据.该表有respond_id,participant_id,answer_text,answer_option_update_date_time. responses_id和participant_id是整数.当我将任何事物分配给participant_id时,它会给出错误,对象无法设置为属性. @interface Coffee
我在SQLite中有一个表我想在该表中插入数据.该表有respond_id,participant_id,answer_text,answer_option_update_date_time. responses_id和participant_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]; } 当我为participant_id分配值时,它会给出错误. 解决方法
NSInteger不是类,它是一个类似int或long的基本类型.在iOS上,NSInteger的类型定义为int,在OS X上,它的类型定义为long.因此,您不应该尝试保留NSInteger.您应该将您的财产声明更改为:
@property (nonatomic,assign) NSInteger participant_Id; 您的coffeeID属性也是如此. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |