2

How to remove [[UIColor grayColor] CGColor] stupid warning?

[self setValue:
     [[UIColor grayColor] CGColor] 
          forKeyPath:[NSString stringWithFormat:@"_View_%@%d.layer.borderColor", 
              i>=10?@"":@"0", i]];

Incompatible pointer types sending 'CGColorRef' (aka 'struct CGColor *') to parameter of type 'id'

thanks.

elp
  • 8,021
  • 7
  • 61
  • 120

2 Answers2

2

cast CGColor to id type:

[self setValue:
     (id)[[UIColor grayColor] CGColor] 
          forKeyPath:[NSString stringWithFormat:@"_View_%@%d.layer.borderColor", 
              i>=10?@"":@"0", i]];
Oladya Kane
  • 877
  • 7
  • 9
  • Works, but it's strange because if I use `id color = [[UIColor grayColor] CGColor];` warning remain the same... – elp Nov 27 '12 at 11:54
  • cast it (as he said) :: the problem is that CGColorRef isnt really an NSObject and thus not compatible (with arc for example. it doesnt know retain/release/isEqual ...) -- for methods that accept that know this, this isnt a problem so above code is save – Daij-Djan Nov 27 '12 at 12:13
0

This will perform same as above code.

[self setValue:
 (id)[[UIColor grayColor] CGColor] 
      forKeyPath:[NSString stringWithFormat:@"_View_%02d.layer.borderColor", i]];
Rahul Singh
  • 101
  • 5