Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A framework for composing and transforming streams of values.
Objective-C

This branch is 2677 commits behind ReactiveCocoa:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
GHAPIDemo
RACExtensions
RACiOSDemo
ReactiveCocoaFramework
external
.gitignore
.gitmodules
CONTRIBUTING.md
LICENSE.md
README.md

README.md

ReactiveCocoa

ReactiveCocoa (RAC) is a framework for composing and transforming streams of values.

No seriously, what is it?

Check out the announcement blog post for a ton more info.

Getting Started

RAC uses some submodules. Once you've cloned the repository, be sure to run git submodule update --recursive --init to pull them all down.

Then checkout the Mac or iOS demos.

Examples

Observe changes to properties:

[RACAble(self.username) subscribeNext:^(NSString *newName) {
    NSLog(@"%@", newName);
}];

Filter changes:

[[[[RACAble(self.username) 
    distinctUntilChanged] 
    take:3] 
    filter:^(NSString *newUsername) {
        return [newUsername isEqualToString:@"joshaber"];
    }] 
    subscribeNext:^(id _) {
        NSLog(@"Hi me!");
    }];

Derive properties:

RAC(self.createEnabled) = [RACSignal 
    combineLatest:@[ RACAble(self.password), RACAble(self.passwordConfirmation) ] 
    reduce:^(NSString *password, NSString *passwordConfirm) {
        return @([passwordConfirm isEqualToString:password]);
    }];

Chain asynchronous calls:

[[RACSignal 
    flatten:@[ [client fetchUserRepos], [client fetchOrgRepos] ]] 
    subscribeCompleted:^{
        NSLog(@"They're both done!");
    }];
[[[[client 
    loginUser] 
    flattenMap:^(User *user) {
        return [client loadCachedMessagesForUser:user];
    }]
    flattenMap:^(NSArray *messages) {
        return [client fetchMessagesAfterMessage:messages.lastObject];
    }]
    subscribeCompleted:^{
        NSLog(@"Fetched all messages.");
    }];

Easily move between different queues:

RAC(self.imageView.image) = [[[[client 
    fetchUserWithUsername:@"joshaber"] 
    deliverOn:[RACScheduler scheduler]]
    map:^(User *user) {
        // This is on a background queue.
        return [[NSImage alloc] initWithContentsOfURL:user.avatarURL];
    }]
    // Now the assignment will be done on the main thread.
    deliverOn:RACScheduler.mainThreadScheduler]

Foundation Support

There are a number of categories that provide RAC-based bridges to standard Foundation classes. They're not included as part of the framework proper in order to keep the framework size down.

You can find them in RACExtensions. To use them, simply add them directly to your project as needed.

License

MIT License

Something went wrong with that request. Please try again.