Use Designated Initializer Style
Use designated initializer style when initializing a structure.
For example, consider CKFlexboxComponent
which accepts a collection of children. Each CKFlexboxComponentChild
is a structure that consists of a position
, a component
, and a size
. Instead of initializing contiguous members:
CKComponent *const component =[CKFlexboxComponentnewWithView:{}size:{}style:{}children:{{{0, 0},leftComponent,{50, 50},},{{50, 0},centerComponent,{50, 50},},{{100, 0},rightComponent,{50, 50},},}]
You should initialize each member by name:
CKComponent *const component =[CKFlexboxComponentnewWithView:{}size:{}style:{}children:{{.component = leftComponent,.size = {50, 50},},{.position = {50, 0},.component = centerComponent,.size = {50, 50},},{.position = {100, 0},.component = rightComponent,.size = {50, 50},},}]
Omitted members will be initialized to 0. In the example above the first child explicitly omits position
since it will be initialized to {0, 0}
by default.