1

I try to use new @propertyWrappers on arguments defined in type initializer like in the below code:

init(@Inject services: TodoServiceContainer? = nil) {
    service = services?.todoService
}

But Xcode doesn't compile such code and throws such error

Closure captures '_services' before it is declared

Using the same property wrapper on function after initialization of object works great

func inject(@Inject services: TodoServiceContainer? = nil) {
        service = services?.todoService
} 

Also if I comment usage of argument inside initializer body code compiles ok

init(@Inject services: TodoServiceContainer? = nil) {
    //service = services?.todoService
}

But I would like to use initializer argument inside body to initialize some properties

Is it even possible?

enter image description here

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143

0 Answers0