开发者

passing argument ... makes integer from pointer without a cast

开发者 https://www.devze.com 2023-02-18 11:31 出处:网络
How can I solve this problem? code: [NSNumber numberWithInteger:[buttonStatsInSection objectAtIndex:row]]

How can I solve this problem?

code:

[NSNumber numberWithInteger:[buttonStatsInSection objectAtIndex:row]]

warning: passing argument 1 of 'numberWithInteger:' makes int开发者_高级运维eger from pointer without a cast

Thanks.


numberWithInteger: needs you to give it an int to create the NSNumber. You are giving it an object, because objectAtIndex: returns an object.

Even if the object you have at that row is an NSNumber, or anything else, you still need to get an actual int data type out of it somehow.

For example, if the object you get back is an NSNumber, you could have something like this in the end:

NSNumber * myNSNum = [buttonStatsInSection objectAtIndex:row];
int myInt = [myNSNum intValue];
[NSNumber numberWithInteger:myInt];


Why are you creating a new NSNumber object? Do you really want a copy of it, or do you just want a reference to it? What do you plan to do with it? If you want a copy, you can just do:

NSNumber* copy = (NSNumber*)[[buttonStatsInSection objextAtIndex:row] copy];

Otherwise just do:

NSNumber* num = (NSNumber*)[buttonStatsInSection objextAtIndex:row];

Either way it isn't necessary to go through the process of extracting the int value and the converting it right back to an NSNumber

0

精彩评论

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