19
REACTIVECOCOA A Dive into Functional Reactive Programming

ReactiveCocoa for CincyCocoaDev Meetup

Embed Size (px)

DESCRIPTION

An intro to ReactiveCocoa for iOS

Citation preview

Page 1: ReactiveCocoa for CincyCocoaDev Meetup

REACTIVECOCOAA Dive into Functional Reactive Programming

Page 3: ReactiveCocoa for CincyCocoaDev Meetup

STATE OF STATE

• KVO

• Callback Blocks

• Delegates

• Target-action mechanisms

• Notifications

Page 4: ReactiveCocoa for CincyCocoaDev Meetup

CODE

Page 5: ReactiveCocoa for CincyCocoaDev Meetup

RAC CODE

Page 6: ReactiveCocoa for CincyCocoaDev Meetup

RAC DEFINED

• RAC Definition

• RAC Birth

• My History

Page 7: ReactiveCocoa for CincyCocoaDev Meetup

TERMS

• RACStream

• RACSignal

• RACSubscriber

• RACCommand

• RACSequence [Soon to be deprecated]

Page 8: ReactiveCocoa for CincyCocoaDev Meetup

STREAMS

• Base class for the interesting classes

• Pipes of values retrieved sequentially

• Composed and operated on with operators

Page 9: ReactiveCocoa for CincyCocoaDev Meetup

SIGNALS• Push driven stream

• Must be subscribed to

• Sends 3 types of events

• Next

• Error

• Complete

Page 10: ReactiveCocoa for CincyCocoaDev Meetup

TRANSFORMINGOPERATORS

• Mapping - map:

• Filtering - filter:

• Concatenating - concat:

• Flattening - flatten:

• Mapping and Flattening - flattenMap:

Page 11: ReactiveCocoa for CincyCocoaDev Meetup

COMBINING OPERATORS

• +merge:

• +combineLatest:

• +switchToLatest:

Page 12: ReactiveCocoa for CincyCocoaDev Meetup

SUBSCRIBER

• subscribeNext:error:completed:

Page 13: ReactiveCocoa for CincyCocoaDev Meetup

CODE

Page 14: ReactiveCocoa for CincyCocoaDev Meetup

COMMANDS

• Creates and subscribes to a signal in response to action.

• Can be disabled based on a signal

Page 15: ReactiveCocoa for CincyCocoaDev Meetup

CODE

Page 16: ReactiveCocoa for CincyCocoaDev Meetup

MISC GEMS• @weakify/@strongify

• RAC() is a macro that makes the binding look nicer.

• [RACObserve(self, event) subscribeNext:^(Type *vale) {...}];

• [[self rac_signalForSelector:@selector(selector:) fromProtocol:@protocol(SomeDelegate)]

• RACTupleUnpack(Type1 * var1, Type2 * var2…) = args;

Page 17: ReactiveCocoa for CincyCocoaDev Meetup

MVVMUnder MVVM, the view and view controller become

formally connected; we treat them as one. Views still don’t have references to the model, but neither do controllers. Instead, they reference the view model.

Page 18: ReactiveCocoa for CincyCocoaDev Meetup

–Lillian Smith

“When you stop learning, stop listening, stop looking and asking questions, always

new questions, then it is time to die.”

Page 19: ReactiveCocoa for CincyCocoaDev Meetup

RESOURCES• Ray Wenderlich - 2 part tutorial plus YouTube video

• ReactiveCocoa at github.- Read the documentation folder

• Ash Furrow’s blog - teehan+lax

• Ash Furrow’s book - Functional Reactive Programming on iOS (Lean Pub)

• Warning: Some blogs and Stackoverflow posts are based on older versions of RAC. Make sure it refers to 2.x