CGFloat array help - iPhone dev

here is my code:

CGFloat components[8];//[8];// = {  0.6, 0.6, 0.6, 0.5, 0.4, 0.4, 0.4, 0.5 };
if ([appDelegate.graphType isEqualToString:@"response"])
{
    CGFloat components[8] = {  0.2, 0.2, 0.2, 0.5, 0.5, 0.5, 0.5, 0.5 };
}
else 
{
    if ([appDelegate.graphType isEqualToString:@"uptime"])
    {
        CGFloat components[8] = {  0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
    }
    else
    {
        CGFloat components[8] = {  0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
    }
}

      

Basically, I want to paint different gradients based on different types of graphs. However, xCode shows me that the CGFloat [8] components from the if / else statements are not used and ignore its values. Any ideas what the problem is

+2


source to share


1 answer


You declare new component arrays in each if / else block. You don't want to do this, you just want to assign values ​​to an already declared array of components.

Something like this should work:



CGFloat components[8];

const CGFloat components1[8] = {  0.2, 0.2, 0.2, 0.5, 0.5, 0.5, 0.5, 0.5 };
const CGGloat components2[8] = {  0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
const CGFloat components3[8] = {  0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };

if ([appDelegate.graphType isEqualToString:@"response"])
{
    memcpy(components,components1, 8*sizeof(CGFloat));
}
else 
{
    if ([appDelegate.graphType isEqualToString:@"uptime"])
    {
             memcpy(components,components2, 8*sizeof(CGFloat));
    }
    else
    {
             memcpy(components,components3, 8*sizeof(CGFloat));
    }
}

      

+9


source







All Articles