如果您将数组包装在一个结构中,它就会变得可分配。
typedef struct
{
CGFloat c[8];
} Components;
// declare and initialise in one go:
Components comps = {
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.15
};
// declare and then assign:
Components comps;
comps = (Components){
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.15
};
// To access elements:
comps.c[3] = 0.04;
如果您使用这种方法,您还可以Components从方法返回结构,这意味着您可以创建函数来初始化和分配给结构,例如:
Components comps = SomeFunction(inputData);
DoSomethingWithComponents(comps);
comps = GetSomeOtherComps(moreInput);
// etc.