1

I realized that for loops are deprecated with the old system but have not been able to figure out what the problem is .. I've created this for loop in objective c now I would like to know if this with the introduction of xCode 7.3 way implement the for loop is deprecated or not. If the answer is you could give me an example of this my cycle on how to make non-deprecated? Yet I could not understand where is my mistake

for (NSInteger i = 0; i < self.valueForBar.count; i++ ) {


        // Creazione delle barre in movimento

        CGFloat columnWidth = 25;
        CGFloat maximumValueOfBar = self.frame.size.height;
        CGFloat index = [[self.valueForBar objectAtIndex:i] floatValue] /100;
        CGFloat barWidth = 20;

        UIBezierPath *path = [UIBezierPath bezierPath];
        [path moveToPoint:CGPointMake(15 +columnWidth *i,maximumValueOfBar -25)];
        [path addLineToPoint:CGPointMake(15 +columnWidth *i,(maximumValueOfBar -25) - maximumValueOfBar * index)];


        CAShapeLayer *pathLayer = [CAShapeLayer layer];
        pathLayer.frame = self.scrollChart.bounds;
        pathLayer.path = path.CGPath;
        pathLayer.strokeColor = self.fillBarColor.CGColor;
        pathLayer.fillColor = nil;
        pathLayer.lineWidth = barWidth;
        pathLayer.lineJoin = kCALineJoinBevel;


        [self.scrollChart.layer addSublayer:pathLayer];


        CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        pathAnimation.duration = 1;
        pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
        pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
        [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];

    }
kAiN
  • 2,559
  • 1
  • 26
  • 54

1 Answers1

1

C style for loops are deprecated in Swift, not in Objective C. Objective C is a super set of C and conforms to the C standard, so the C style for loop is never going away, especially since Apple doesn't release many Objective C changes these days.

Josh Homann
  • 15,933
  • 3
  • 30
  • 33
  • Ok but i working in objective C that problems should I have? My code is not regular? I do not use Swift but i use Objective C – kAiN Dec 07 '16 at 08:16
  • Is it not compiling and if so what is the error. If it runs is it running the expected number of times? Did you put a NSLog or a break point in the loop to check? – Josh Homann Dec 07 '16 at 08:20
  • So .. I'll explain .. my code works perfectly, but some people had told me it was deprecated. You're telling me that this code is deprecated ONLY for SWIFT and not to Objective-C. Did I get it right? I'm working on Objective C and then wanted to know if I'm working well or if I should change something :) – kAiN Dec 07 '16 at 08:22
  • 1
    Don't believe *some people*. – vadian Dec 07 '16 at 08:24
  • So I can continue to work quietly ... my code is correct? Forgive my stupid question but I had doubts – kAiN Dec 07 '16 at 08:25
  • perfect ... Thanks a lot for the explanation and reassurance: D are four days that are on that for loop to get some results and now that I managed to complete my goal these doubts have scared me ahahaha – kAiN Dec 07 '16 at 08:30