[ad_1]
I am trying to initialize the WidgetKit
struct WidgetInfo
for unit testing a function that takes WidgetInfo
as an argument:
let widgetInfo = WidgetInfo()
This gives me the error:
‘WidgetInfo’ cannot be constructed because it has no accessible initializers
I tried adding:
extension WidgetInfo {
public init() {}
}
and I can initialize – yay! But then I try to set one of its properties
widgetInfo.family = .systemSmall
and get the error: Cannot assign to property: ‘family’ is a ‘let’ constant
I tried another initializer with arguments:
extension WidgetInfo {
public init(family: WidgetFamily, kind: String) {
self.family = family
self.kind = kind
}
}
and I get the error: ‘let’ property ‘family’ may not be initialized directly; use “self.init(…)” or “self = …” instead
I’m stuck – is there a way for me to initialize WidgetInfo
? Or another way to test a function that takes WidgetInfo
as an argument?
[ad_2]