> For the complete documentation index, see [llms.txt](https://docs.drivequant.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.drivequant.com/challenge/ios/get-started.md).

# Get started

{% hint style="info" %}
Methods presented in this part are available in the `DriveKitChallenge` class
{% endhint %}

## **Prerequisite**

Before starting DriveKit Challenge module integration, make sure that you have [initialized DriveKit](/get-started-drivekit/ios.md), especially if you have [disable the SDK auto-initialization](/get-started-drivekit/ios/advanced-configurations.md#manually-initialize-the-sdk).

{% hint style="danger" %}
If you use DriveKit Challenge without having initialized DriveKit, the SDK may not work properly in your application.
{% endhint %}

## **Integration**

### **Get framework**&#x20;

To add the Challenge module to your app using **Swift Package Manager**, add `DriveKitChallenge` from repository: `https://github.com/DriveQuantPublic/drivekit-sdk-spm.git` as dependency.

## Synchronize list of challenges

To synchronize the list of challenges, call the following method:

```swift
DriveKitChallenge.shared.getChallenges(
   type: SynchronizationType = .defaultSync,
   completionHandler: @escaping (ChallengesSyncStatus, [DKChallenge]) -> Void
)
```

[ChallengesSyncStatus](/challenge/ios/references-ios.md#challengessyncstatus) and [DKChallenge](/challenge/ios/references-ios.md#dkchallenge) models are described in the [References](/challenge/ios/references-ios.md) part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-ios/blob/master/DriveKitChallengeUI/ChallengeList/ViewModel/ChallengeListViewModel.swift#L45) of our DriveKit Demo App to see how it is implemented.
{% endhint %}

## Retrieve local challenge list

You can retrieve the list of challenges stored in the DriveKit local database by calling the previous method but with the `SynchronizationType` parameter to `.cache`.

## Synchronize challenge detail

You need to call the following method if you want to get more details and statistics about a defined challenge:

```swift
DriveKitChallenge.shared.getChallengeDetail(
   challengeId: String,
   type: SynchronizationType = .defaultSync,
   completionHandler: @escaping (ChallengeDetailSyncStatus, DKChallengeDetail?) -> Void
)
```

This method have the following parameters:

| Field               | Type                | Description                                                                                                                                                                                                                                                                          |
| ------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| challengeId         | String              | Unique identifier of the challenge                                                                                                                                                                                                                                                   |
| synchronizationType | SynchronizationType | <p>Can be <code>.defaultSync</code> or <code>.cache</code>.</p><p>- <code>.defaultSync</code> will synchronize the challenge detail by calling the DriveQuant servers</p><p>- <code>.cache</code> will retrieve the challenge detail already synchronized in the local database.</p> |

[ChallengeDetailSyncStatus](/challenge/ios/references-ios.md#challengedetailsyncstatus) and [DKChallengeDetail](/challenge/ios/references-ios.md#dkchallengedetail) models are described in the [References](/challenge/ios/references-ios.md) part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-ios/blob/master/DriveKitChallengeUI/ChallengeList/ViewModel/ChallengeDetailViewModel.swift#L153) of our DriveKit Demo App to see how it is implemented.
{% endhint %}

## Retrieve local challenge detail data

You can retrieve the details of a given challenge stored in the DriveKit local database by calling the previous method but with the `SynchronizationType` parameter to `.cache`.

## Join a challenge

To be able to join a given challenge, you can call the following method:

```swift
DriveKitChallenge.shared.joinChallenge(
   challengeId: String,
   completionHandler: @escaping (JoinChallengeSyncStatus) -> Void
)
```

This method have the following parameter:

| Field       | Type   | Description                        |
| ----------- | ------ | ---------------------------------- |
| challengeId | String | Unique identifier of the challenge |

[JoinChallengeSyncStatus](/challenge/ios/references-ios.md#joinchallengesyncstatus) enum values are described in the [References](/challenge/ios/references-ios.md) part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-ios/blob/master/DriveKitChallengeUI/ChallengeList/ViewModel/ChallengeParticipationViewModel.swift#L132) of our DriveKit Demo App to see how it is implemented.
{% endhint %}
