class DIFormInit {
let i: Int
init(i: Int) {
self.i = i
}
}
class DIFormProperty {
var i: Int!
}
class DIFormMustHave {
@MustInjected(file: #file, line: #line)
var i: Int
}
@propertyWrapper struct MustInjected<Value> { | |
private var _value: Value! = nil | |
#if DEBUG | |
let line: UInt | |
let file: StaticString | |
#endif | |
@available(*, unavailable) | |
init(wrappedValue: @autoclosure @escaping () -> Value) { | |
self._value = nil | |
line = #line | |
file = #file | |
} | |
var wrappedValue: Value { | |
mutating get { | |
#if DEBUG | |
precondition(_value != nil, "This property must be inject before access", file: file, line: line) | |
#endif | |
return _value | |
} | |
set { | |
#if DEBUG | |
precondition(_value == nil, "This property is actcully a Let property", file: file, line: line) | |
#endif | |
_value = newValue | |
} | |
} | |
} | |
extension MustInjected { | |
init(file: StaticString, line: UInt) { | |
self._value = nil | |
#if DEBUG | |
self.file = file | |
self.line = line | |
#endif | |
} | |
} |