PreconditionFailure Cannot cast AnyObject to AnyObject
- Dominant language
- Objective-C
- Stars
- 3.8k
- Forks
- 316
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/VitaliyZaharenko/GooglePromisesModulesIssue)
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.
```swift
//module
public class SomeModuleClass {
var blabla: String = "blaCls"
public init() {}
}
public protocol ModuleProviderProtocol {
func getObjectAsClass() -> Promise
}
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 {
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
Contributor guide
Assessment
This issue has not been assessed yet.