blog

Image of code from ilya-pavlov

Found on GitHub: ObjectiveSugar

by

Octocat logo

Marin Usalj has written a collection of extensions for the NSNumber, NSArray, NSSet, NSString, and NSDictionary classes that brings many of the commonly used methods from their Ruby counterparts such as each or times. If you’re familiar with Ruby and doing some iOS or Mac development these extensions can definitely save you some work.

Check out the samples below, pulled from the ObjectiveSugar ReadMe and add the code to your project using Cocoapods.

[@3 times:^{
  NSLog(@"Hello World!");
}];
// Hello World!
// Hello World!
// Hello World!

or:

NSArray *cars = [@"Testarossa", @"F50", @"F458 Italia"];
// or NSSet *cars = [NSSet setWithObjects:@"Testarossa", @"F50", @"F458 Italia", nil];
[cars map:^id(id car){
    return @([[car substringToIndex:1] isEqualToString:@"F"]);
}];
// NO (Testarossa)
// YES (F50)
// YES (F458 Italia)

+ more