Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need explanation of weird syntax

i follow tutorial and find this code:

self.imageView.frame = (CGRect){.origin = CGPointMake(0.0f, 0.0f), .size = image.size};

Its pretty clear What it does, but I'm not understand syntax of this line of code. First time i see something like this: .size = image.size. In dot syntax i expect to see something in front of dot, like self.view, but what is meaning of .size?

Second question is - why there is round brackets and after them curly brackets? I never seen structure like that (){}; before.

My question may sound silly, but now I'm a bit confused, can someone provide explanation? Thank you.

like image 687
Evgeniy Kleban Avatar asked Apr 29 '14 18:04

Evgeniy Kleban


People also ask

What Is syntax explain?

syntax, the arrangement of words in sentences, clauses, and phrases, and the study of the formation of sentences and the relationship of their component parts.

What is the need of syntax?

"Syntax skills help us understand how sentences work—the meanings behind word order, structure, and punctuation. By providing support for developing syntax skills, we can help readers understand increasingly complex texts" (Learner Variability Project).

What is an example of incorrect syntax?

Four common syntax errors For example: Incorrect: “She enjoys cooking her family and her dog.” Correct: “She enjoys cooking, her family, and her dog.” Using sentence fragments instead of complete sentences is sometimes okay when writing is meant to be conversational.


1 Answers

This is the Designated Initializer syntax of C structs. The parentheses () are used to cast the struct to a CGRect. As Martin R points out, the cast is not necessary unless you use compound literal syntax, where you don’t name the parameters.

like image 117
Zev Eisenberg Avatar answered Oct 13 '22 09:10

Zev Eisenberg