---
title: Leveraging SwiftUI
description: Shows a basic example of how to integrate the DaVinci module with SwiftUI by using a ViewModel to manage the UI state.
component: orchsdks
page_id: orchsdks:davinci:usage/ios/04-leveraging-swiftui
canonical_url: https://developer.pingidentity.com/orchsdks/davinci/usage/ios/04-leveraging-swiftui.html
revdate: Fri, 9 Jan 2026 17:23:51 +0000
keywords: ["DaVinci", "iOS", "SwiftUI", "ViewModel", "Integration"]
---

# Leveraging SwiftUI

[icon: circle-check, set=far]PingOne [icon: apple, set=fab]iOS

The following shows how you could use the DaVinci module with SwiftUI:

ViewModel

```swift
//Define State that listen by the View

@Published var state: Node = EmptyNode()

//Start the DaVinci flow
let next = await daVinci.start()

//Update the state
state = next

func next(node: ContinueNode) {
   val next = await node.next()
   state = next

}
```

View

```swift
if let node = state.node {
    switch node {
    case is ContinueNode:
        // Handle ContinueNode case
        break
    case is ErrorNode:
        // Handle Error case
        break
    case is FailureNode:
        // Handle Failure case
        break
    case is SuccessNode:
        // Handle Success case
        break
    default:
        break
    }
}
```
