I am wondering how I might go about using the ReactiveCocoa
library to RAC
-ify UIApplicationDelegate
lifecycle events.
Since the most important one is - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
, that seems like a logical place to start to me.
The basic idea, if I understand correctly, would be to create a RACSignal
that would encapsulate the event (application finished launching with these options), send it either serially through a pipeline or in parallel to multiple "application start handlers" and then merge all of their outputs - if serially, then only continue when each returns YES
, if parallel, if (handler1 == YES && handler2 == YES ...)
- and then return
the combined response in the actual UIApplicationDelegate
.
However, I am fuzzy on the precise details of how this would be accomplished - which is probably evident from my line of questioning.
Any examples, either in real code or just pseudo-code, would be greatly appreciated. It would for me (and probably others) serve a dual purpose: 1) the stated one, and 2) provide an example of how to RAC
-ify a non-UI-driven event (well, that's not even exactly true, but I think you see what I mean).
I figured out that I could wrap the delegate methods using signalForSelector
carefully.
I learned from this answer to use rac_signalForSelector
before setting the delegate.
For UIApplicationDelegate
it is potentially a bit more complicated because we don't usually set UIApplication
delegate
directly but instead specify a class in the main.m
file in the case of Objective-C or in main.swift
in the case of Swift.
However, I believe that if the setup is done in the AppDelegate
class itself, and it is assigned in the main
file, this will satisfy the requirement stated above.
Another choice is to add the methods to the interface of a new Objective-C category or Swift extension to a UIResponder
subclass.