You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2019. It is now read-only.
Underscore.m is a small utility library to facilitate working with common data structures in Objective-C.
It tries to encourage chaining by eschewing the square bracket]]]]]].
It is inspired by the awesome underscore.js.
Real world example
// First, let's compose a twitter search requestNSURL *twitterSearch = [NSURLURLWithString:@"https://search.twitter.com/search.json?q=@SoundCloud&rpp=100"];
// ... then we fetch us some json ...NSData *data = [NSDatadataWithContentsOfURL:twitterSearch];
// ... and parse it.NSDictionary *json = [NSJSONSerializationJSONObjectWithData:data
options:kNilOptionserror:NULL];
// This is where the fun starts!NSArray *tweets = [json valueForKey:@"results"];
NSArray *processed = _array(tweets)
// Let's make sure that we only operate on NSDictionaries, you never// know with these APIs ;-)
.filter(Underscore.isDictionary)
// Remove all tweets that are in English
.reject(^BOOL (NSDictionary *tweet) {
return [[tweet valueForKey:@"iso_language_code"] isEqualToString:@"en"];
})
// Create a simple string representation for every tweet
.map(^NSString *(NSDictionary *tweet) {
NSString *name = [tweet valueForKey:@"from_user_name"];
NSString *text = [tweet valueForKey:@"text"];
return [NSStringstringWithFormat:@"%@: %@", name, text];
})
.unwrap;
Documentation
Documentation for Underscore.m can be found on the website.