0

I have an reversed array

 NSArray *reversedArray = [[arr reverseObjectEnumerator] allObjects];

It contains following value

Reversed Array: ( 0, 0, "0.1702998", "0.4936719", 0, "0.1861508", )

So the value which are comming are dynamic, So i want the first non zero value from this array.

How can i do this?

2
  • Do both 0 and "0.0000000" count as zero? Commented Nov 7, 2011 at 17:11
  • Yes i do not need both of value. Commented Nov 7, 2011 at 17:12

1 Answer 1

1
double firstNonZeroValue = 0.0;
for (NSString* stringValue in [array reverseObjectEnumerator]) {
    double value = [stringValue doubleValue];
    if (value != 0.0) {
        firstNonZeroValue = value;
        break;
    }
}

if (firstNonZeroValue != 0.0) {
    ... yay found a non zero value ...
}
Sign up to request clarification or add additional context in comments.

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.