开发者

NSNumber to float error

I am not sure why I am getting the following error:

NSNumber to float error

the height doesn't complain anything, it's just the width... why?

Here's my code:

@interface Embed : RKObject {
    NSString * _url;
    NSString * _original;
    NSNumber * _width;
    NSNumber * _h开发者_运维技巧eight;
}

@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

not sure why it's a CGFloat, never convert it to CGFloat anywhere else


The error message would imply that it thinks the 'width' message, as posted to the objectAtIndex:0 returns a CGFloat, not an NSNumber.

It's possible it has made an incorrect guess about the thing you're calling width on, so assuming you have your object defined correctly you probably just need to give the compiler the correct hint, e.g. (broken down to make it clear where the cast goes):

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


The barely discernable error leads me to think that your -width method is returning a CGFloat rather than an NSNumber*.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜