Value of type 'AnimationView?' has no member 'setAnimation'
Asked Answered
G

2

6

I am trying to add an animation to my application using Lottie but I get this error and I still do not know how to solve it.

import UIKit
import Lottie

class ViewController: UIViewController {
    @IBOutlet var animationView: AnimationView!

    override func viewDidLoad() {
        super.viewDidLoad()
        startAnimation()
    }
    
    func startAnimation(){
        animationView.setAnimation(named: "data")//error1
        animationView.loopAnimation = true//error2
        animationView.play()
    }
}

The error that comes out:

Value of type 'AnimationView?' has no member 'setAnimation'

Value of type 'AnimationView?' has no member 'loopAnimation'

enter image description here

German answered 29/5, 2019 at 22:59 Comment(0)
C
-2

it seems you are new in swift.

this happen because the class AnimationView does not have function named setAnimation(named:) or variable named loopAnimation, you need to declare them inside AnimationView class

Cates answered 29/5, 2019 at 23:8 Comment(1)
This answer is unhelpful. He could be using swift package manager or Cocoapods and is just looking for the updated syntax.Dissuasion
S
5

I'm using lottie-ios version 3.1.3 and ran into this same issue. After a little bit of digging I found that the syntax has changed. For your first error you need to change the code to the following:

animationView.animation = Animation.named("spineffectloader")

For the second error you should change the code to the following:

animationView.loopMode = .loop
Secularism answered 18/10, 2019 at 12:24 Comment(0)
C
-2

it seems you are new in swift.

this happen because the class AnimationView does not have function named setAnimation(named:) or variable named loopAnimation, you need to declare them inside AnimationView class

Cates answered 29/5, 2019 at 23:8 Comment(1)
This answer is unhelpful. He could be using swift package manager or Cocoapods and is just looking for the updated syntax.Dissuasion

© 2022 - 2024 — McMap. All rights reserved.