macspeed macspeed - 2 months ago 16x
Objective-C Question

Collection element of type 'void *' is not an Objective-C object

Im trying to add the a gradient view to my background on for an iOS app.

Using the pod

I am adding a GradientLayer to my background under

- (void)viewDidLoad {
[super viewDidLoad];
UIColor *startColor = [UIColor uig_emeraldWaterStartColor];
UIColor *endColor = [UIColor uig_emeraldWaterEndColor];

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(self.view.frame.size.width, 0);
gradient.colors = @[(id)[startColor CGColor], (id)[endColor CGColor], nil];

[self.view.layer insertSublayer:gradient atIndex:0];

The error occurs on line
gradients.colors = @[(id)[startColor CGColor], (id)[endColor CGColor], nil];

error :

Collection element of type 'void *' is not an Objective-C object.

Thanks for any assistance.


Remove the nil from the end of the array. You can't put nil in an Objective-C array, nor is it necessary in @[] literals. So:

gradient.colors = @[(id)[startColor CGColor], (id)[endColor CGColor]];