2016-12-07 50 views
1

我意识到for循环被旧系统弃用,但一直未能找出问题所在。我已经创建了这个for循环的目标c现在我想知道如果这个与xCode 7.3的方式引入实现for循环是否被弃用。如果答案是你可以给我一个关于如何使不被弃用的循环的例子吗?但我不明白哪里是我的错For循环在xCode 7.3上弃用

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"]; 

    } 
+0

这些C风格的循环在** Swift **(仅)中已弃用。 – vadian

回答

1

for循环空调风格的雨燕已被弃用,而不是目的C.目标C是一个超集C和符合C标准,所以C风格循环永远不会消失,尤其是因为Apple最近没有发布很多Objective C更改。

+0

好吧,但我在目标C工作,我应该有问题?我的代码不规则?我不使用Swift,但我使用Objective C – kAiN

+0

它是不是编译,如果是的话,错误是什么。如果它运行的是它运行预期的次数?你有没有在循环中加入一个NSLog或一个断点来检查? –

+0

所以..我会解释..我的代码完美工作,但有些人告诉我它已被弃用。你告诉我,这个代码已被弃用,只适用于SWIFT而不适用于Objective-C。我是否正确?我正在研究Objective C,然后想知道我是否工作得很好,或者我应该改变什么:) – kAiN