hmlongco / Resolver

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

Could not cast value of type 'Swift.Optional<Swift.Optional<Any>>' to 'Swift.String' #163

Open KC-218 opened 2 years ago

KC-218 commented 2 years ago

Sorry, my app crash and get this error.
And this is my code.

@objc protocol Animal {
    var name: String { get }
    @objc optional var running: Bool { get }
}

class Horse: Animal {
    let name: String
    let running: Bool

    init(name: String, running: Bool) {
        self.name = name
        self.running = running
    }

    convenience init(name: String) {
        self.init(name: name, running: false)
    }
}

class ResolverParameterInjectionVC: UIViewController, Resolving {

    override func viewDidLoad() {
        super.viewDidLoad()

        let smallHorse: Animal = Resolver.resolve(name: "small", args: "Spirit")
        let bigHorse: Animal = Resolver.resolve(name: "big", args: ["name": "Lucky", "running": true])        
    }

}

extension Resolver {
    public static func registerResolverParameterInjectionVC() {

        register { (_, args) in
            Horse(name: args.get())
        }.implements(Animal.self, name: "small")

        register { (_, args) in
            Horse(name: args("name"), running: args("running"))
        }.implements(Animal.self, name: "big")
    }
}
revo1111 commented 1 year ago

1

majie776 commented 1 year ago

这是来自QQ邮箱的自动回复邮件。   邮件已收到

revo1111 commented 1 year ago

1