Closed sutefan1 closed 7 years ago
Normally you shouldn't have to do the cast. RxApplicationDelegateProxy
confirms to UIApplicationDelegate
and gives you access to all the methods and properties defined in the UIApplicationDelegate
protocol.
What about properties which are defined in AppDelegate
? How can I access them without cast?
Ah, sorry I misunderstood. You can access the original app delegate via forwardToDelegate()
.
So if your AppDelegate
has a customProperty
property, you can access it like this:
if
let delegateProxy = UIApplication.shared.delegate as? DelegateProxy,
let appDelegate = delegateProxy.forwardToDelegate() as? AppDelegate {
print(appDelegate.customProperty)
}
@pixeldock is there a way to avoid doing any casting? just have it return Appdelegate while still having the ability to observe for changes
@shams-ahmed The DelegateProxy
class is part of RxCocoa. I don‘t see any way around the casting.
I need to access my AppDelegate, but when I do this
let appDelegate = UIApplication.shared.delegate as! AppDelegate
, an error occurs that I can't castRxAppState.RxApplicationDelegateProxy
toAppDelegate
.