Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KC-218 opened this issue Sep 12, 2022 · 3 comments

Comments

@KC-218
Copy link

KC-218 commented Sep 12, 2022

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
Copy link

revo1111 commented Aug 6, 2023

1

@majie776
Copy link

majie776 commented Aug 6, 2023 via email

@revo1111
Copy link

revo1111 commented Aug 6, 2023

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants