0
[self backgroundImages][[NSNumber numberWithInt:barMetrics]] = backgroundImage;

How can I solve this warning?

enter image description here

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
Erhan
  • 908
  • 8
  • 19

2 Answers2

2

To get rid of the warning use

[NSNumber numberWithInteger:metrics]

or

[NSNumber numberWithInt:(int)metrics]

because metrics is an NSInteger and numberWithInt accepts int not NSInteger.

But what you really want is

[self backgroundImages][(int)metrics];
peko
  • 11,267
  • 4
  • 33
  • 48
  • Technically, you'll also want to cast the item in the array as a `UIImage`, since objects in `NSArray` are `id`: `UIImage *image = (UIImage *)[self background][NSNumber numberWithInteger:metrics]` – cleverbit Dec 11 '13 at 12:01
  • @richarddas A cast there would serve no purpose. – jlehr Dec 11 '13 at 13:07
1

You try to pass NSNumber as a index to your array but you should pass int instead:

[self backgroundImages][It should be an int number] 

I assume backgroundImages is array. BarMetrics is an UIBarMetrics type you cannot pass it as an int.

You can do something like that:

int i = -1;
if (barMetrics == UIBarMetricsDefault)
    i = 0;
if (barMetrics == UIBarMetricsLandscapePhone)
    i = 1;
// and so on....
[self backgroundImages][i] 
Greg
  • 25,317
  • 6
  • 53
  • 62