2

I'm getting this error only when using Swift and I was wondering if anybody else has this issue currently

Extra argument 'usingSpringWithDamping' in call

UIView.animateWithDuration(NSTimeInterval(doctorPracticeDuration), delay: 0.0, usingSpringWithDamping: 0.3, initialSpringVelocity: textAnimationVelocity, options: .CurveEaseInOut, animations: {}, completion: {success in })

I'm using Xcode 6 beta 7

It's interesting that this works:

UIView.animateWithDuration(NSTimeInterval(doctorPracticeDuration), delay: 0.0, options: .Repeat, animations: {}, completion: {finished in })

Is it possible that using a spring animation isn't supported yet in Swift? I know its still early on...

Stephen Sweriduk
  • 278
  • 6
  • 11
  • 1
    "Is it possible that using a spring animation isn't supported yet in Swift" No, it isn't possible; it is supported. The problem, as always in Swift, is that you are not casting to the correct parameter data types. – matt Sep 08 '14 at 03:37
  • You don't provide enough information, such as what `textAnimationVelocity` is. That's crucial, because Swift is strict about parameter data types. – matt Sep 09 '14 at 15:16

5 Answers5

3

It took me a lot of time to fix this out. Swift has awful error messages. In my case the problem was related to the completion block.

I had this in there:

label.transform = CGAffineTransformMakeTranslation(label.frame.size*2, 0)

Notice the issue ? I was multiplying CGSize by 2. Fixed that and it worked.

My advice is to check your animation/completion block, cause the problem could be most likely from there.

Sebyddd
  • 4,305
  • 2
  • 39
  • 43
  • Thanks for that comment, worked out for me too. Had an error in UIColor constructor that was used in completion block: self.myView.backgroundColor = UIColor(0.92, 0.92, 0.92, 1) Had to replace it with: self.myView.backgroundColor = UIColor(red:0.92, green:0.92, blue:0.92, alpha:1) But to figure out what's wrong, had to move the code outside of completion block, correct it and then move it back there. – Anton Kryvenko Jan 23 '15 at 16:33
2

solution:

let doctorPracticeDuration : NSTimeInterval = 1.0
let delay :NSTimeInterval = 1.0
let damping : CGFloat = 0.3
let textAnimationVelocity : CGFloat = 0.5


UIView.animateWithDuration(doctorPracticeDuration,
     delay: 0.0, 
     usingSpringWithDamping: damping, 
     initialSpringVelocity: textAnimationVelocity, 
     options: .CurveEaseInOut, 
     animations: {}, 
     completion: {success in })

Because both usingSpringWithDamping and initialSpringVelocity are CGFloat. please refer to this

What is happening here is that CGFloat is a typealias for either Float or Double depending on whether you're building for 32 or 64-bits. This is exactly how Objective-C works, but is problematic in Swift because Swift doesn't allow implicit conversions.

We're aware of this problem and consider it to be serious: we are evaluating several different solutions right now and will roll one out in a later beta. As you notice, you can cope with this today by casting to Double. This is inelegant but effective :-)

-Chris

from https://devforums.apple.com/message/998222

James Zaghini
  • 3,895
  • 4
  • 45
  • 61
guoleii
  • 496
  • 6
  • 15
  • add explicit declaration with duration and delay, I didn't get errors as @Kyle so missed the type for both duration and delay. But he is right the explicit declaration is preferred. – guoleii Sep 08 '14 at 23:15
0

I ran across this issue and the above solution didn't fix it. It was because you need to make sure you are using NSTimeInterval for both duration and delay as well. So the solution above is correct, but make sure you are using the correct argument types for all parameters.

Kyle
  • 21
  • 4
0
  UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: nil, animations: { }, completion: {(animated:Bool) -> () in transitionContext.completeTransition(true) });

I ran across similar problem, the above line worked for me. To me the problem is the completion block missing parameter declaration. With declaration of block parameters in full set( name,type and parenthesis) , it will work.

jx ch
  • 55
  • 8
0

This error has just pushed me over the edge.. Why bother waste time trying to guess what the actual error is, just use this, and bridge it over to swift:

@interface UIView (SFU)

+ (void)animate:(double)duration delay:(double)delay damping:(double)damping velocity:(double)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

@end

@implementation UIView (SFU)

+ (void)animate:(double)duration delay:(double)delay damping:(double)damping velocity:(double)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
{
    [self animateWithDuration:(NSTimeInterval)duration
                        delay:(NSTimeInterval)delay
       usingSpringWithDamping:(CGFloat)damping
        initialSpringVelocity:(CGFloat)velocity
                      options:options
                   animations:animations
                   completion:completion];
}

@end

No more errors:

UIView.animate(
    transitionDuration(transitionContext),
    delay: 0,
    damping: 1.2,
    velocity: 15,
    options: .allZeros,
    animations: {
        srcVC.view.center.x += srcVC.view.bounds.width
    }) { finished in
        transitionContext.completeTransition(finished)
}
Mazyod
  • 22,319
  • 10
  • 92
  • 157