Core Animation stops animation on app relaunch

On one of my projects I discovered a bug in a never-ending animation I had set up. Whenever the app was suspended (such as when you multitask and open another app), on relaunching the app the animation was frozen. After some investigating, I discovered that with Core Animation you need to set a flag on the CABasicAnimation class called removedOnCompletion to NO otherwise the animation will get cleaned up when it gets suspended.

Objective-C:

CABasicAnimation *dartWiggleAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
dartWiggleAnimation.fromValue =
   [NSValue valueWithCGPoint:CGPointMake(self.center.x-DART_WIGGLE_HALF, self.center.y+DART_CENTER_H_OFFSET)];
dartWiggleAnimation.toValue =
   [NSValue valueWithCGPoint:CGPointMake(self.center.x+DART_WIGGLE_HALF, self.center.y+DART_CENTER_H_OFFSET)];
dartWiggleAnimation.timingFunction =
   [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; 
dartWiggleAnimation.duration = 0.4;
dartWiggleAnimation.repeatCount = HUGE_VALF;
dartWiggleAnimation.autoreverses = YES;
dartWiggleAnimation.removedOnCompletion = NO;
[[nextDart layer] addAnimation:dartWiggleAnimation forKey:@"dartWiggle"];

Swift:


        let dartWiggleAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.position))
        dartWiggleAnimation.fromValue = CGPoint(x: self.center.x - DART_WIGGLE_HALF, y: self.center.y + DART_CENTER_H_OFFSET)
        dartWiggleAnimation.toValue = CGPoint(x: self.center.x + DART_WIGGLE_HALF, y: self.center.y + DART_CENTER_H_OFFSET)
        dartWiggleAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        dartWiggleAnimation.duration = 0.4
        dartWiggleAnimation.repeatCount = Float.greatestFiniteMagnitude
        dartWiggleAnimation.autoreverses = true
        dartWiggleAnimation.isRemovedOnCompletion = false
        nextDart.layer.add(dartWiggleAnimation, forKey: "dartWiggle")

Does this seem like a bug or a feature?

Reverting your library from a beta of iTunes

As an iPhone and iPad developer, Apple often present you with beta versions to install which sometimes require you to also install a beta version of iTunes. Of course the contents of these beta versions are under strict non-disclosure agreements but the process of rolling back isn’t so I’ll quickly explain how to do it…

When you installed the beta, it will upgrade your iTunes library database but if you try to downgrade back to the old version at a later date you’ll be presented with an error message saying that iTunes cannot read your library.

Don’t panic! The beta version has just moved your library database to a backup folder and with a simple drag and drop you can have your old library database up and running again. Your old database should be found in ~/Music/iTunes/Previous iTunes Libraries dated with when you upgraded. Just drag that back into ~/Music/iTunes renaming it to iTunes Library.itl (you’ll probably need to delete the existing iTunes Library.itl file too as that belonged to the beta version and you just uninstalled that).

That’s all you need to do to get your old iTunes library working again. Just before you begin make sure you back up everything!