![](/img/trans.png)
[英]Receiver type 'FBSDKError' (aka 'enum FBSDKError') is not an Objective-C class
[英]Objective-C - Receiver type 'NSInteger' (aka 'long') is not an Objective-C class & Receiver type 'NSDecimal' is not an Objective-C class
我收到标题中的错误,我不知道为什么....
。H
@interface ItemData : NSObject
@property (nonatomic,assign) NSInteger tagId;
@property (nonatomic,strong) NSMutableString *deviceId;
@property (nonatomic,strong) NSDecimal *latitude;
@property (nonatomic,strong) NSDecimal *longitude;
@end
.M
#import <Foundation/Foundation.h>
#import "ItemData.h"
@implementation ItemData
-(id)init
{
if(self = [super init])
{
//TODO: Fix Commented out items
_tagId = [[NSInteger alloc] init];
_deviceId = [[NSMutableString alloc] init];
_latitude = [[NSDecimal alloc] init];
_longitude = [[NSDecimal alloc] init];
}
return self;
}
@end
我不明白我做错了什么...有人可以帮帮我吗?
NSInteger
和NSDecimal
都不是类,而是标量的类型。 您不能将消息发送到此类型的“对象”(在C的意义上,而不是OOP意义上)。 因此,不要使用+alloc
和-init…
构造它们。
你有两种可能性:
A.使用(OOP)对象而不是标量
@property (nonatomic,assign) NSNumber *tagId;
@property (nonatomic,strong) NSDecimalNumber *latitude;
然后您可以像往常一样为对象分配引用:
_tagId = @0; // Or whatever you want.
_latitude = [NSDecimalNumber zero];
B.只需指定一个值
_tagId = 0; // Or whatever you want. There is no nil for integers
这适用于整数,但对于小数则不好,因为它们是具有私有组件的struct
,并且没有创建它们的函数。 但是,您可以创建NSDecimalNumber
实例对象(如A中所示)并使用-decimalValue
获取小数值。
_latitude = [[NSDecimalNumber zero] decimalValue];
NSDecimal
的使用似乎对我来说是错误的。 你为什么要用它? 通常经度和纬度是double
,另一个是标量类型,可以将其视为具有值的整数。 十进制浮点对象用于财务软件。
NSInteger是
typedef long NSInteger;
这应该解释“NSInteger(又名'long')”并且它等效于64位长(long int)C数据类型。 它不是OC类,这就是为什么你不能做(+)alloc和( - )init。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.