# iOS Player
Guide to integrating the dotLottie iOS player. Covers supported devices, Swift Package Manager installation, and basic usage in SwiftUI and UIKit.

# Getting Started with the iOS Player

In this tutorial, you will install the iOS player and display your first Lottie animation in a SwiftUI or UIKit application.

<p align="center">
  <img src="https://user-images.githubusercontent.com/23125742/201124166-c2a0bc2a-018b-463b-b291-944fb767b5c2.png" />
</p>

## Supported Devices

This package supports the following minimum platform versions:

- **iOS / iPadOS:** 13.0+
- **macOS:** 11.0+
- **tvOS:** 13.0+
- **watchOS:** 7.0+
- **visionOS:** 1.0+

## Installation

Via the Swift Package Manager:

In the package finder in Xcode, search for LottieFiles/dotlottie-ios or use the full Github path: [https://github.com/LottieFiles/dotlottie-ios](https://github.com/LottieFiles/dotlottie-ios)

Then import the framework:

```swift
import DotLottie
```

## SwiftUI — DotLottiePlayerView (Recommended)

`DotLottiePlayerView` is the recommended SwiftUI view. It uses a declarative modifier API.

### Load from the asset bundle

```swift
struct AnimationView: View {
    var body: some View {
        DotLottiePlayerView(animation: DotLottieAnimation(
            fileName: "cool_animation",
            config: AnimationConfig(autoplay: true, loop: true)
        ))
        .looping()
        .playing()
        .frame(width: 300, height: 300)
    }
}
```

### Load from a URL

```swift
struct AnimationView: View {
    var body: some View {
        DotLottiePlayerView({
            try await DotLottieAnimation(
                webURL: "https://lottie.host/link.lottie",
                config: AnimationConfig(autoplay: true, loop: true)
            )
        }, placeholder: {
            ProgressView()
        })
        .looping()
        .playing()
        .frame(width: 300, height: 300)
    }
}
```

## SwiftUI — DotLottieAnimation with .view()

You can also use the lower-level `DotLottieAnimation` view model directly:

```swift
struct AnimationView: View {
    var body: some View {
        DotLottieAnimation(
            fileName: "cool_animation",
            config: AnimationConfig(autoplay: true, loop: true)
        ).view()
    }
}
```

### Load from a URL

```swift
struct AnimationView: View {
    var body: some View {
        DotLottieAnimation(
            webURL: "https://lottie.host/link.lottie",
            config: AnimationConfig(autoplay: true, loop: true)
        ).view()
    }
}
```

### Load from a JSON string

```swift
struct AnimationView: View {
    var body: some View {
        DotLottieAnimation(
            animationData: "{\"v\":\"4.8.0\",\"meta\":{\"g\":\"LottieFiles AE...\"}}",
            config: AnimationConfig(autoplay: true, loop: true)
        ).view()
    }
}
```

## UIKit — DotLottiePlayerUIView (Recommended)

`DotLottiePlayerUIView` is the recommended UIKit view with convenience initializers and a property-based API.

```swift
class AnimationViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let playerView = DotLottiePlayerUIView(
            name: "cool_animation",
            config: AnimationConfig(autoplay: true, loop: true)
        )
        playerView.frame = CGRect(x: 50, y: 100, width: 300, height: 300)
        view.addSubview(playerView)
    }
}
```

### Load from a URL

```swift
let playerView = DotLottiePlayerUIView(
    url: URL(string: "https://lottie.host/link.lottie")!,
    config: AnimationConfig(autoplay: true, loop: true)
)
```

## UIKit — DotLottieAnimation with view()

You can also use the lower-level `DotLottieAnimation` approach:

```swift
class AnimationViewController: UIViewController {
    var simpleVM = DotLottieAnimation(
        webURL: "https://lottie.host/link.lottie",
        config: AnimationConfig(autoplay: true, loop: false)
    )

    override func viewWillAppear(_ animated: Bool) {
        let dotLottieView = simpleVM.view()
        view.addSubview(dotLottieView)
    }
}
```
