This article is suitable for children who have a certain RAC foundation to do the query from time to time, so this article does not explain in detail.

First, common classes

  • 1. RACSiganl signal class.

    • RACEmptySignal: an empty signal used to implement the RACSignal +empty method;
    • RACReturnSignal: unary signal used to implement the RACSignal +return: method;
    • RACDynamicSignal: a dynamic signal that uses a block – to implement the subscription behavior. We created an instance of this class using RACSignal’s +createSignal: method.
    • RACErrorSignal: error signal used to implement RACSignal’s +error: method;
    • RACChannelTerminal: A terminal that represents a RACChannel and is used for bidirectional binding.
  • 2. RACSubscriber subscriber

  • RACDisposable is used to unsubscribe or clean up resources and is triggered automatically when the signal is sent or when it is sent incorrectly.

    • RACSerialDisposable: used as a disposable container, can contain a Disposable and allow this Disposable to be swapped out by atomic operations;
    • RACKVOTrampoline: represents a KVO observation and can be used to stop an observation;
    • RACCompoundDisposable: It can contain multiple Disposable objects and supports manual addition and removal of Disposable objects
    • RACScopedDisposable: Calls its own -Dispose method when it is dealloc.
  • 4. RACSubject signal provider, which can act as signal and send signal.

    • RACGroupedSignal: a grouping signal used to implement the grouping function of RACSignal.
    • RACBehaviorSubject: a signal replays the last value that, when subscribed, sends to the subscriber the value it last received;
    • RACReplaySubject: Replays the signal, saves the sent values, and resends them to the subscriber when subscribed.
  • The RACTuple tuple class, similar to NSArray, wraps values.

  • 6, The collection class in RAC

  • 7, RACCommand RAC used for event processing class, can be how the event processing, how the event data transfer, wrapped in this class, it can be very convenient to monitor the event execution process.

  • 8. RACMulticastConnection Is used when a signal is subscribed multiple times. This class is used to ensure that the signal is created without multiple calls to the block used to create the signal.

  • 9, RACScheduler RAC queue, with GCD encapsulation.

    • RACImmediateScheduler: The only scheduler that supported synchronous execution;
    • RACQueueScheduler: an abstract queue scheduler that asynchronously schedules all tasks in a GCD serial queue;
    • RACTargetQueueScheduler: Inherits from RACQueueScheduler and asynchronously schedules all tasks in a serial queue targeting an arbitrary GCD queue;
    • RACSubscriptionScheduler: A scheduler used only to schedule subscriptions.

Second, common usage

  • Rac_signalForSelector: Replaces the proxy
  • rac_valuesAndChangesForKeyPath: KVO
  • Rac_signalForControlEvents: Listens to events
  • Rac_addObserverForName instead of notification
  • Rac_textSignal: Listens for text changes in a text box
  • Rac_liftSelector: withSignalsFromArray: Signals: when the incoming Signals (array) signal, each signal sendNext at least once, will go to trigger the first selector parameter method.

Common macros

  • RAC(TARGET, [KEYPATH, [NIL_VALUE]]) : Used to bind a property of an object
  • RACObserve(self, name) : Listens on a property of an object and returns a signal.
  • @ weakify (Obj) and @ strongify (Obj)
  • RACTuplePack: Wraps data as RACTuple (tuple class)
  • RACTupleUnpack: Unpack RACTuple (tuple class) into corresponding data
  • RACChannelTo A terminal for bidirectional binding

Four, common operation methods

  • A flattenMap is used to map source signal content into new content.
  • Concat combines signals in a certain order. When multiple signals are sent, sequential signals are received
  • Then is used to connect two signals, and when the first signal is complete, the signal returned by then is connected.
  • Merge Merges multiple signals into one signal, which is called when any signal has a new value
  • ZipWith compresses two signals into a single signal, and the next event of the compressed stream is triggered only when both signals simultaneously emit signal contents and combine the contents of the two signals into a single tuple.
  • CombineLatest: To combine multiple signals and get the latest values of each signal, each combined signal must have sendNext at least once to trigger the combined signal.
  • Reduce aggregation: The content used for signal sending is a tuple, aggregating the values of the signal sending tuple into a value

  • Filter: indicates that you can obtain signals that meet the conditions.
  • Ignore: Signals that ignore certain values.
  • DistinctUntilChanged: signaled when there is a significant change between the previous value and the current value, otherwise ignored.
  • Take: Take N signals from the beginning
  • TakeLast: To get the last N signals, the subscriber must call completion, because only completion knows how many signals there are.
  • TakeUntil :(RACSignal *): Get a signal until a signal execution is complete
  • Skip :(NSUInteger): Several signals are skipped and not accepted.
  • SwitchToLatest: Used to obtain the latest signal sent by signalOfSignals.

  • DoNext: This Block is executed before Next
  • DoCompleted: This Block is executed before sendCompleted is executed

  • Timeout: allows a signal to automatically report an error after a certain period of time.

  • Interval: Sends signals at intervals
  • Delay Delays sending next.

  • Retry retry: On failure, the block in the creation signal is re-executed until it succeeds.

  • Replay: When a signal is subscribed multiple times, the content is played repeatedly
  • Throttle: When a signal is sent frequently, you can use throttling to stop sending signal content for a certain period of time and obtain the latest signal content after a certain period of time.

5. Ui-category (Common summary)

  • 1. Rac_prepareForReuseSignal: Relevant UI is used when reuse is required: MKAnnotationView, UICollectionReusableView, UITableViewCell, UITableViewHeaderFooterView

  • Rac_buttonClickedSignal: UIActionSheet, UIAlertView

  • 3, rac_command: button class, refresh class related commands replace related UI: UIBarButtonItem, UIButton, UIRefreshControl

  • Rac_signalForControlEvents: Control event triggers related UI: UIControl

  • 5, rac_gestureSignal UIGestureRecognizer event processing signal related UI: UIGestureRecognizer

  • Rac_imageSelectedSignal selects the image signal-related UI: UIImagePickerController

  • 7, rac_textSignal related UI: UITextField, UITextView

  • 8. API for bidirectional binding

    • Rac_channelForControlEvents: key: nilValue: Related UI: UIControl class
    • Rac_newDateChannelWithNilValue: related UI: UIDatePicker
    • Rac_newSelectedSegmentIndexChannelWithNilValue: related UI: UISegmentedControl
    • Rac_newValueChannelWithNilValue: related UI: UISlider, UIStepper
    • Rac_newOnChannel Related UI: UISwitch
    • Rac_newTextChannel related UI: UITextField

6. Foundation-category

  • 1, NSArray
    • Rac_sequence signal set
  • 2, NSData
    • Rac_readContentsOfURL: Options: Scheduler: has more thread Settings than OC
  • 3, NSDictionary
    • Rac_sequence don’t explain
    • Rac_keySequence key collection
    • Rac_valueSequence collection value
  • 4, NSEnumerator
    • Rac_sequence don’t explain
  • 5, NSFileHandle
    • Rac_readInBackground is known by name
  • 6, NSIndexSet
    • Rac_sequence don’t explain
  • 7, NSInvocation
    • Rac_setArgument: atIndex: Sets parameters
    • Rac_argumentAtIndex takes some argument
    • Rac_returnValue The return value of the associated method
  • 8 NSNotificationCenter.
    • Rac_addObserverForName: object: registration notification
  • 9 NSObject.
    • The rac_willDeallocSignal that is fired when the object is destroyed
    • Rac_description debug with
    • Rac_observeKeyPath: options: Observer: block: listens for an event
    • Rac_liftSelector: withSignals: All signals are executed by next
    • Rac_signalForSelector: Replaces a method
    • Rac_signalForSelector :(SEL) Selector fromProtocol: replaces the proxy
  • 9 NSOrderedSet.
    • Rac_sequence don’t explain
  • 10 and NSSet
    • Rac_sequence don’t explain
  • 11, nsstrings
    • Rac_keyPathComponents retrieves all parts of a path
    • The final part of rac_keyPathByDeletingLastKeyPathComponent delete path
    • The first part rac_keyPathByDeletingFirstKeyPathComponent delete path
    • Rac_sequence not explained (character)
    • Rac_readContentsOfURL: usedEncoding: Scheduler: compared to OC multithreaded call
  • 12, NSURLConnection
    • Rac_sendAsynchronousRequest Initiates asynchronous requests
  • 13, NSUserDefaults
    • Rac_channelTerminalForKey is used for bi-directional binding, which is one end

This article is prepared by the author Wang Longshuai, reprint please retain the copyright website, thank you for your understanding and sharing, let life become better!

Vii. Reference materials

www.cocoachina.com/ios/2016010… www.jianshu.com/p/d262f2c55… www.jianshu.com/p/da9698064… Mp.weixin.qq.com/s?__biz=MzA… www.jianshu.com/p/87ef6720a… www.jianshu.com/p/e10e5ca41… www.th7.cn/Program/IOS…