Search code examples
objective-cxcodensshadow

Creating NSShadow makes an error


I'm making a white shadow in Objective-C and using the code

NSShadow *myShadow = [[NSShadow alloc]init];
[myShadow setShadowColor: [UIColor whiteColor]];

and it seems to work fine, but when I'm trying to shorten it to

NSShadow *myShadow = [[[NSShadow alloc]init] setShadowColor: [UIColor whiteColor]];

I get the error message "Initializing 'NSShadow *__strong' with an expression of incompatible type 'void'" Anyone knows what is happening here?


Solution

  • What's happening is the compiler doesn't like a variable of type NSShadow * being assigned void (the return type of setShadowColor and that expression as a whole).

    You will need to use your two-line approach, which is easier to read and therefore maintain.