在iPhone App中分配NSInteger属性

在iPhone App中分配NSInteger属性,第1张

概述我在SQLite中有一个表我想在该表中插入数据.该表有respond_id,participant_id,answer_text,answer_option_update_date_time. responses_id和participant_id是整数.当我将任何事物分配给participant_id时,它会给出错误,对象无法设置为属性. @interface Coffee : NSObject 我在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属性也是如此.

总结

以上是内存溢出为你收集整理的在iPhone App中分配NSInteger属性全部内容,希望文章能够帮你解决在iPhone App中分配NSInteger属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1058995.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存