Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top