1

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?

turingtested
  • 6,356
  • 7
  • 32
  • 47

1 Answers1

1

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.

Droppy
  • 9,691
  • 1
  • 20
  • 27
  • Nice answer, thanks! But it would be even nicer if Apple made a class method called "shadowWithColor:" so I could write NSShadow *myShadow = [NSShadow shadowWithColor: [UIColor whiteColor]]; – turingtested Aug 01 '14 at 08:33
  • ... looks like a job for a category to might like to write ;-) – Droppy Aug 01 '14 at 08:43