0

Im trying to access these values from array storing float:

color_Array = @[@[@96.0f,@178.0f,@228.0f]];

i need to get the first value of the inner first array and i tried :

float *first = [color_Array objectAtIndex:[indexPath.row][0]];

Im just getting an error : expected identifier

Any suggestions ?

1
  • You are fetching an array from 0th index. So store resultant into an array named as "SubArray" again. From "SubArray" get float values. Commented Nov 3, 2015 at 14:06

2 Answers 2

1

Here's a breakdown of the data structure you've created:

NSArray *color_Array = @[@[@96.0f,@178.0f,@228.0f]];
NSArray *subArray = [color_Array objectAtIndex:0];
NSNumber *firstNumber = [subArray objectAtIndex:0];
float first = [firstNumber floatValue];

You can combine them as you like. For example:

float f = [color_Array[0][0] floatValue];
Sign up to request clarification or add additional context in comments.

Comments

0

You can retrieve by this way

NSArray *color_Array = @[@[@96.0f,@178.0f,@228.0f]];
for (NSArray *rgbArray in color_Array) {
    NSLog(@"%@",rgbArray);
    float r = [rgbArray[0] floatValue];
    float g = [rgbArray[1] floatValue];
    float b = [rgbArray[2] floatValue];
    NSLog(@"r:%f,g:%f,b:%f",r,g,b);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.