iphone - 在 iPhone App 中分配 NSInteger 属性

标签 iphone objective-c ios xcode sqlite

我在 SQLite 中有一个表,我想在该表中插入数据。该表有 responses_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 不是一个类,它是一个基本类型,如 intlong。在 iOS 上 NSIntegertypedef 编辑为 int,在 OS X 上它被 typedef 编辑为 。因此,您不应尝试保留 NSInteger。您应该将属性(property)声明更改为:

@property (nonatomic, assign) NSInteger participant_Id;

您的 coffeeID 属性也是如此。

关于iphone - 在 iPhone App 中分配 NSInteger 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12275423/

相关文章:

iphone - 在辅助线程中运行 Cocoa block

ios - NSURLConnection connectionWithRequest :delegate and sendAsynchronousRequest:queue:completionHandler? 之间的主要区别是什么

Iphone:下载游戏关卡(或一般的额外功能)

objective-c - 将 UIButton 放入 UITableView 中

ios - 在 UITableView 中获取输入 onclick

ios - 在使用 SnapKit 的 iOS 上,为什么 subview 的原点不是其父 View 的原点?

iphone - 如何获取给定 PFUser 的 facebook 用户名?

ios - 代码 : Reload UITableViewCell

ios - 未调用嵌套 UITextField 的 UITextFieldDelegate

objective-c - dispatch_async 自定义队列永远不会退出 block