---
updatedAt: 2026-05-27T06:20:12.000Z
agentTools:
  projectIndex: https://developers.bazaarvoice.com/v1.0-MobileSDK/llms.txt
---

# Swift

This section outlines how to implement Content Coach in iOS devices using Swift.

The **Swift** implementation uses the `BVContentCoachQueryResponse` and `BVContentCoachSubmissionResponse` handlers to process `Result` types (Success or Failure).

# Retrieve AI-generated topic suggestions

To retrieve AI-generated topic suggestions for a product within the review submission form, initiate a `BVReviewTokensQuery` and execute it using `.async()` as shown below:

```swift
// 1. Create and configure the query
let query = BVReviewTokensQuery(productId: "product_id")
    .configure(BVReviewTokensQueryTest.config) // Apply your BV configuration
    .handler { (response: BVContentCoachQueryResponse<BVReviewTokens>) in
        switch response {
        case .success(let tokensResponse):
            // Check for API-level errors within a successful HTTP response
            guard let status = tokensResponse.status,
                  let error = BVContentCoachError("\(status)", message: tokensResponse.detail) else {
                
                // Extract and use the tokens
                guard let tokens = tokensResponse.tokens else {
                    print("No tokens returned")
                    return
                }
                print(tokens)
                return
            }
            print("\(error.code) : \(error.message)")
            
        case .failure(let errors):
            // Handle network or system failures
            errors.forEach { (error: Error) in
                guard let bverror: BVError = error as? BVError else { return }
                print(bverror.message)
            }
        }
    }

// 2. Execute the query
query.async()

```

# Retrieve matched topics

Once the user types at least 5 words into the Review text box, trigger `BVMatchedTokensSubmission` to pass the live texts. Use this to evaluate which words match the topic suggestions from `BVReviewTokensQuery`. Ensure the `BVMatchedTokens` data object is nested inside `BVMatchedTokensSubmission` as shown below:

```swift
// 1. Define the tokens payload with the current review text
let tokens = BVMatchedTokens(productId: "product_id", reviewText: "review_text")

guard let tokensSubmission = BVMatchedTokensSubmission(tokens) else { return }

// 2. Configure and attach the handler
tokensSubmission
    .configure(BVMatchedTokensQueryTest.config)
    .handler { (response: BVContentCoachSubmissionResponse<BVMatchedTokens>) in
        switch response {
        case .success(let tokensResponse):
            guard let status = tokensResponse.status,
                  let error = BVContentCoachError("\(status)", message: tokensResponse.detail) else {
                
                guard let tokens = tokensResponse.tokens else {
                    print("No tokens returned")
                    return
                }
                print(tokens) // UI updates for matched tokens go here
                return
            }
            print("\(error.code) : \(error.message)")
            
        case .failure(let errors):
            errors.forEach { (error: Error) in
                guard let bverror: BVError = error as? BVError else { return }
                print(bverror.message)
            }
        }
    }

// 3. Execute the submission
tokensSubmission.async()

```

<br />