指向整数转换的不兼容指针 [英] Incompatible pointer to integer conversion
问题描述
我正在学习 Objective-C,但在项目中遇到了一些问题.我用一个方法创建了一个类来创建一个新对象,我在尝试创建一个新对象时遇到了一些问题,我不知道在这种情况下什么是最好的属性.
Im learning Objective-C and im having some problems with a project. I made a class with a method to create a new object and im having some issues trying to create a new Object, i dont know what is the best kind of proporties in this case.
类.h
#import <Foundation/Foundation.h>
@interface ObrasData : NSObject
@property (strong) NSNumber *ID;
@property (assign) char presupuesto;
@property (assign) char descripcion;
@property (assign) char aasm_state;
@property (assign) char clienteID;
- (id)initWithID:(NSNumber*)ID presupuesto:(char)presupuesto description:(char)description aasm_state:(char)aasm_state clienteID:(char)clienteID;
@end
类.m
@implementation ObrasData
@synthesize ID = _ID;
@synthesize presupuesto = _presupuesto;
@synthesize descripcion = _descripcion;
@synthesize aasm_state = _aasm_state;
@synthesize clienteID = _clienteID;
- (id)initWithID:(NSNumber *)ID presupuesto:(char)presupuesto description:(char)description aasm_state:(char)aasm_state clienteID:(char)clienteID{
if ((self = [super init])) {
self.ID = ID;
self.presupuesto = presupuesto;
self.descripcion = description;
self.aasm_state = aasm_state;
self.clienteID = clienteID;
}
return self;
}
这里我有错误:不兼容的整数转换指针"
And here im having the error: "Incompatible pointer to integer conversion"
ObrasData *obra1 = [[ObrasData alloc] initWithID:[NSNumber numberWithInt:1] presupuesto:100 description:@"obra de prueba" aasm_state:@"En proceso" clienteID:@"dm2"];
我做错了什么?我想稍后在列表视图上显示该对象
What im doing wrong? I want to show later the object on a listview
推荐答案
Class.h
#import <Foundation/Foundation.h>
@interface ObrasData : NSObject
@property (strong) NSNumber *ID;
@property (strong) NSString *presupuesto;
@property (strong) NSString *descripcion;
@property (strong) NSString *aasm_state;
@property (strong) NSString *clienteID;
- (id)initWithID:(NSNumber*)ID presupuesto:(NSString *)presupuesto description:(NSString *)description aasm_state:(NSString *)aasm_state clienteID:(NSString *)clienteID;
@end
类.m
@implementation ObrasData
@synthesize ID = _ID;
@synthesize presupuesto = _presupuesto;
@synthesize descripcion = _descripcion;
@synthesize aasm_state = _aasm_state;
@synthesize clienteID = _clienteID;
- (id)initWithID:(NSNumber *)ID presupuesto:(NSString *)presupuesto description:(NSString *)description aasm_state:(NSString *)aasm_state clienteID:(NSString *)clienteID{
if ((self = [super init])) {
self.ID = ID;
self.presupuesto = presupuesto;
self.descripcion = description;
self.aasm_state = aasm_state;
self.clienteID = clienteID;
}
return self;
}
并像这样调用:ObrasData *obra1 = [[ObrasData alloc] initWithID:[NSNumber numberWithInt:1] presupuesto:@"100" description:@"obra de prueba" aasm_state:@"En proceso" clienteID:@"dm2"];
and call like this : ObrasData *obra1 = [[ObrasData alloc] initWithID:[NSNumber numberWithInt:1] presupuesto:@"100" description:@"obra de prueba" aasm_state:@"En proceso" clienteID:@"dm2"];
这篇关于指向整数转换的不兼容指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!