Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's this {{0,0},{w,h}} doing?

I stumbled upon this piece of code today:

CGRect rect = {{0,0},{w,h}};

Here, I would have used a CGRectMake. But what does this thing in rambled brackets do? What kind of special-syntax is that? None of my objective-c books ever mentioned that.

like image 552
Thanks Avatar asked May 14 '09 20:05

Thanks


1 Answers

It's a standard C structure initialization construct. Any structure can be initialized at declaration time by providing its contents in order within curly braces like this. Because a CGRect contains a CGPoint and a CGSize, you use one set of braces for the CGRect, then another set for each of CGPoint & CGSize.

like image 184
Jim Dovey Avatar answered Nov 01 '22 12:11

Jim Dovey