CGRectMake Alternative

I saw this alternative to using CGRectMake() to initialize the CGRect variable:

CGRect frame = (CGRect) {0,0,10,10};

My question is: how does CGRect frame = (CGRect){0,0,10,10}; ? What is going on behind the scenes? It looks like the c-style array ( {x,y,w,h} ) is initialized, which is then passed as a CGRect structure - is this correct? If so, how can I create an array of style c as a structure?

NB I am not asking if it is advisable to use the above alternative to CGRectMake() , I just want to understand why / how it works.

+6
source share
3 answers

This is the so-called composite literal. You can learn more about them in this article by Mike Ashe: Friday Q & A 2011-02-18: complex literals .

+7
source

U can use the following:

 CGRect rect = CGRectFromString(@"{{0, 0}, {612, 892}}"); // it contents { CGPoint origin;CGSize size;}; NSLog(@"rect : %@",NSStringFromCGRect(rect)); 
+1
source

Check this:

 CGPoint origin = {10, 20}; CGSize size = {100, 200}; CGRect rect = {origin, size}; 
+1
source

Source: https://habr.com/ru/post/922262/


All Articles