IOS SDK should have initializer simple initializers
Right now the SDK generated only has init with decoder.
public init(from decoder: any Decoder)
This limits us in generating the Previews for the views. Please consider adding additional inits with all variables in the struct
-
Priyatham Anisetty commented
Right now I have this struct
public struct InventoryItem: Decodable, Sendable ,Hashable, Equatable, Identifiable {
public var
id: UUIDpublic var
name: Stringpublic var
stockInHand: Doublepublic var
unit: Stringpublic var
lastUpdated: Timestamppublic var
costPerUnit: Doublepublic var
supplierName: String?public var
threshold: Double?
public var inventoryItemKey: InventoryItemKey {
return InventoryItemKey(
id: id
)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public static func == (lhs: InventoryItem, rhs: InventoryItem) -> Bool {
return lhs.id == rhs.id
}
enum CodingKeys: String, CodingKey {
case id
case name
case stockInHand
case unit
case lastUpdated
case costPerUnit
case supplierName
case threshold
}public init(from decoder: any Decoder) throws {
var container = try decoder.container(keyedBy: CodingKeys.self)
let codecHelper = CodecHelper<CodingKeys>()
self.id = try codecHelper.decode(UUID.self, forKey: .id, container: &container)
self.name = try codecHelper.decode(String.self, forKey: .name, container: &container)
self.stockInHand = try codecHelper.decode(Double.self, forKey: .stockInHand, container: &container)
self.unit = try codecHelper.decode(String.self, forKey: .unit, container: &container)
self.lastUpdated = try codecHelper.decode(Timestamp.self, forKey: .lastUpdated, container: &container)
self.costPerUnit = try codecHelper.decode(Double.self, forKey: .costPerUnit, container: &container)
self.supplierName = try codecHelper.decode(String?.self, forKey: .supplierName, container: &container)
self.threshold = try codecHelper.decode(Double?.self, forKey: .threshold, container: &container)
}
}
public var
inventoryItems: [InventoryItem]}
public func ref(
storeId: String) -> QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables> {
var variables = GetAllInventoryForStoreQuery.Variables(storeId:storeId)
let ref = dataConnect.query(name: "getAllInventoryForStore", variables: variables, resultsDataType:GetAllInventoryForStoreQuery.Data.self, publisher: .observableObject)
return ref as! QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables>
}@MainActor
public func execute(
storeId: String) async throws -> OperationResult<GetAllInventoryForStoreQuery.Data> {
var variables = GetAllInventoryForStoreQuery.Variables(storeId:storeId)
let ref = dataConnect.query(name: "getAllInventoryForStore", variables: variables, resultsDataType:GetAllInventoryForStoreQuery.Data.self, publisher: .observableObject)
let refCast = ref as! QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables>
return try await refCast.execute()
}
}I can only init by creating a JSON object serialize it and then pass it to the decoder to decode. it makes me write unnecessary code in my Preview functions.