NSNumber浮动错误

时间:2011-05-09 22:15:56

标签: iphone objective-c ipad

我不确定为什么会收到以下错误: enter image description here

高度不会抱怨什么,只是宽度......为什么?

这是我的代码:

@interface Embed : RKObject {
    NSString * _url;
    NSString * _original;
    NSNumber * _width;
    NSNumber * _height;
}

@property (nonatomic, retain) NSString * url;
@property (nonatomic, retain) NSString * original;
@property (nonatomic, retain) NSNumber * width;
@property (nonatomic, retain) NSNumber * height;

@end

@implementation Embed
@synthesize url = _url;
@synthesize original = _original;
@synthesize width = _width;
@synthesize height = _height;

+ (NSDictionary*) elementToPropertyMappings {
    return [NSDictionary dictionaryWithKeysAndObjects:
            @"url", @"url",
            @"original", @"original",
            @"width", @"width",
            @"height", @"height",
            nil]; 

}

- (void)dealloc
{
    [_url release];
    [_original release];
    [_width release];
    [_height release];
    [super dealloc];
}


@end

不确定为什么它是CGFloat,永远不会将它转换为其他地方的CGFloat

2 个答案:

答案 0 :(得分:1)

错误消息表示它认为发布到objectAtIndex:0的“宽度”消息会返回CGFloat,而不是NSNumber

它有可能对你正在调用宽度的东西做出了错误的猜测,所以假设你正确定义了你的对象,你可能只需要给编译器提供正确的提示,例如: (分解以明确演员的去向):

[
    [
        (MyCorrectType *)[
                             [
                                 [postsObject objectAtIndex:indexPath.row]
                             embeds]
                         objectAtIndex:0] // cast goes with the result of this
    width]
floatValue]

答案 1 :(得分:0)

几乎无法辨别的错误让我认为你的-width方法正在返回CGFloat而不是NSNumber *。