macspeed macspeed - 1 year ago 118
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.

Answer Source

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]];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download