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

PreconditionFailure Cannot cast AnyObject to AnyObject #135

Open
VitaliyZaharenko opened this issue Feb 12, 2020 · 1 comment
Open

PreconditionFailure Cannot cast AnyObject to AnyObject #135

VitaliyZaharenko opened this issue Feb 12, 2020 · 1 comment

Comments

@VitaliyZaharenko
Copy link

VitaliyZaharenko commented Feb 12, 2020

I successfully used Promises in one project until the moment I decided to break it into modules and get "Fatal error: Cannot cast AnyObject to AnyObject" when trying to "then" on promise. It promise returns some class, which implement some public interface.

I created a simplified version of what was happened in the repository on the link

This workspace have a main project and an module as .framework.
For clarity of what was at first in my project, i create SomeMainClass and SomeMainStruct. Also I have protocol, which describe provider, thats return promise parameterized with SomeMainClass, SomeMainClass and it's have MainModuleProvider thats implement this provider interface. On other parts of project I use this provider and call "then" on Promise, that's return this provider. All is work as expected.

On the other part in the module I have SomeModuleClass and SomeModuleStruct, ModuleProviderProtocol thats return Promise and Promise. Main project defines ModuleProvider, which implements ModuleProviderProtocol.

I also have some consumer of this provider in Module. When I'm trying to consume provider, i have precondition failure: Cannot cast AnyObject to AnyObject.

//module
public class SomeModuleClass {
    var blabla: String = "blaCls"
    public init() {}
}
public protocol ModuleProviderProtocol {
    func getObjectAsClass() -> Promise<SomeModuleClass>
}
public class ModuleProviderConsumer {
    var provider: ModuleProviderProtocol
    public init(provider: ModuleProviderProtocol) {
        self.provider = provider
    }
    public func consume() {
        provider.getObjectAsClass().then { objectAsClass in
            print(objectAsClass)
        }
    }
}

// main project 
import PromiseModule
final class ModuleProvider: ModuleProviderProtocol {
    func getObjectAsClass() -> Promise<SomeModuleClass> {
        return Promise { resolve, reject in
            resolve(SomeModuleClass())
        }
    }
}

// usage of consumer,  also in main project
import PromiseModule
let consumer = ModuleProviderConsumer(provider: moduleProvider)
consumer.consume()

Additional Info
Promises: 1.2.8
Xcode: Version 11.3 (11C29)
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Mac Os 10.14.6

@brettcallaghan
Copy link

@VitaliyZaharenko, I ran into the same issue as I was migrating from CocoaPods to Swift Package Manager. It turned out that I was also still importing Promises as a pod. Removing the pod seems to have fixed the issue.

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

2 participants