1

I am analyzing some Objective-C code and found the following:

CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = _fullWidth, .size.height = height}, partialImg);

What is the purpose of {.origin.x = 0.0f, ...}? Is this an object being initialized or a dictionary?

thanks!

pinker
  • 1,283
  • 2
  • 15
  • 32
  • 2
    This is short struct initialization of CGRect. – Greg Dec 24 '13 at 11:51
  • possible duplicate of [How to initialize a struct in ANSI C](http://stackoverflow.com/questions/330793/how-to-initialize-a-struct-in-ansi-c) – jrturton Dec 24 '13 at 11:52

1 Answers1

1

This is the designated initializer syntax of C99, it has nothing to do with Objective C or dictionaries. You use this syntax to initialize "plain" C structures in contexts where calling CGRectMake is not possible - for example, when you initialize a static variable.

Note that in your case you could have used CGRectMake as well for a shorter, easier to read, code:

CGContextDrawImage(bmContext, CGRectMake(0.0f, 0.0f, _fullWidth, height), partialImg);
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523