Changing the Default Product Structure in Swift SDK

The following is what the default product structure looks like according to the Dynamic Yield product feed structure:

public class DefaultRecsProductData: RecsProductData { let productType: ProductType? let groupId: String? let name: String? let url: String? let price: Float? let inStock: Bool? let imageUrl: String? let categories: [String?]? var keywords: [String?]? }

Changing the default using Swift SDK

To add more fields to the product structure:

  1. Create a new class that inherits from RecsProductData.
public class CustomRecsProductData: RecsProductData { var shortColor: String = "yellow" var tShirtNumber: Int = 8 var initials: String = "A.N" }
  1. Set this class as the new default product data structure by calling setDefaultProductDataType().
DYSdk.shared().setDefaultProductDataType(defaultRecsProductData: CustomRecsProductData.self)
  1. After calling setDefaultProductDataType(), whenever chooseVariations is called for recommendation campaigns, the return value includes the fields you added to the new class.

Did this page help you?