# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.drivequant.com/challenge/ios/get-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
