hmlongco / Resolver

Swift Ultralight Dependency Injection / Service Locator framework
MIT License
2.15k stars 190 forks source link

@WeakLazyInjected - Generic parameter 'Service' could not be inferred #111

Closed AppyMike closed 3 years ago

AppyMike commented 3 years ago

Whenever I try to use @WeakLazyInjected property wrapper I always get the error "Generic parameter 'Service' could not be inferred"

Example:

register { TableDelegate() }

class ViewController: UIViewController {
    @WeakLazyInjected var tableDelegate: TableDelegate

   ...
}
class TableDelegate: NSObject, UITableViewDelegate {
  ...
}

Am I missing something in the implmentation?

hmlongco commented 3 years ago

If it's weak it's got to be optional, does it not?

@WeakLazyInjected var tableDelegate: TableDelegate?
AppyMike commented 3 years ago

sorry yes. Apologies for wasting your time.

I have a query related to this though. When using SwiftLint it throws the Weak Delegate Violation on @WeakLazyInjected var tableDelegate: TableDelegate?. Is this actually a violation or is just simply that SwiftLint can't find weak? What I mean is does @WeakLazyInjected effectively inject as weak var?

hmlongco commented 3 years ago

No worries. As to the rest, internally it's weak but SwiftLint doesn't see it that way. It just pattern matches on "delegate" and starts complaining.