Files
divkit/client/ios/Samples
booster 3739f4d359 Added collection view ios sample
commit_hash:0f36266bb814aec8babef2f9ddb2f9333dbd2f1e
2026-02-19 13:42:43 +03:00
..
2025-09-18 12:40:09 +03:00
2025-09-18 12:40:09 +03:00
2025-07-04 00:17:17 +03:00

DivKit in iOS. Quick start.

Build an MVP.

Code-wise, connecting DivKit consists of three parts: initializing DivKitComponents, parsing the JSON file with the layout, and creating DivHostingView or DivView and adding it to your SwiftUI or UIKit hierarchy respectively.

Creating DivKitComponents.

You should create DivKitComponents object and provide the necessary dependencies and handlers.

Creating DivViewSource.

You should create DivViewSource where you need to provide DivKit data. This can be done in the following ways:

  • raw JSON in Dictionary format
  • JSON in Swift.Data format
  • DivData object

Creating DivKit View.

To create DivView (UIKit) or DivHostingView (SwiftUI), you need to provide a previously created DivKitComponents instance to the constructor. Subsequently, you should populate the DivView with the data to be displayed at the appropriate time in UIKit via setSource or provide DivViewSource to DivHostingView constructor in SwiftUI.

Initialization Example:

UIKit

  let divView = DivView(divKitComponents: divKitComponents)
  divView.setSource(
      DivBlockProvider.Source(
          kind: .json(json),
          cardId: cardId
      ),
      debugParams: debugParams,
      shouldResetPreviousCardData: true
  )

SwiftUI

    DivHostingView(
      divkitComponents: DivKitComponents(
        divCustomBlockFactory: SampleDivCustomBlockFactory(),
        urlHandler: SampleDivActionHandler(
          isPresented: $isPresented,
          text: $text
        )
      ),
      source: DivViewSource(kind: .data(sampleData), cardId: "Sample"),
      debugParams: DebugParams(isDebugInfoEnabled: true)
    )