iOS clair couche de UIView

J'ai dessiné quelques lignes dans la propriété de calque de mon UIView.
Mais est-il une méthode pour nettoyer toutes les lignes que j'ai dessiné?

Je veux effacer tout ce qui est dessiné sur la couche de mon point de vue.

J'ai dessiner une ligne avec le code suivant:

- (void)drawLine :(UIView *)drawInView :(CGPoint)startPosition :(CGPoint)endPosition
{
    //draw the line
    linePath = CGPathCreateMutable();
    lineShape = [CAShapeLayer layer];

    lineShape.lineWidth = 1.0f;
    lineShape.lineCap = kCALineCapRound;;
    lineShape.strokeColor = [[UIColor whiteColor] CGColor];

    CGPathMoveToPoint(linePath, NULL, startPosition.x, startPosition.y);
    CGPathAddLineToPoint(linePath, NULL, endPosition.x, endPosition.y);

    lineShape.path = linePath;
    CGPathRelease(linePath);
    [drawInView.layer addSublayer:lineShape];
}

J'ai trouvé un code pour supprimer tous les sous-couches j'ai dessiné.

-(void)clearGraph :(UIView *)viewToClear
{
    for (CALayer *layer in viewToClear.layer.sublayers) {
        [layer removeFromSuperlayer];
    }
}

Mais cela donnera une Exception:

2013-08-28 21:10:18.877 ServerInfo[12861:3f03] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x1f86b3b0> was mutated while being enumerated.'
*** First throw call stack:
(0x336ef3e7 0x3b3ea963 0x336eeec1 0x13f7d 0x158bb 0x340082fb 0x336c4857 0x336c4503 0x336c3177 0x3363623d 0x336360c9 0x33f5a5c3 0x33ffdc45 0x15843 0x34007231 0x3b8370e1 0x3b836fa8)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

J'appelle ma méthode drawline à l'intérieur d'un NSTread. (doParsing méthode pour être précis).

NSThread *myThread =[[NSThread alloc]initWithTarget:self selector:@selector(callTimer) object:nil];
    [myThread start];

- (void)callTimer
{
    NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(doParsing) userInfo:nil repeats:YES];
    [runLoop run];
}

OriginalL'auteur Jasper Fioole | 2013-08-28