blog

Image of code from ilya-pavlov

Found on GitHub: ObjectiveSugar

by | Dec 7, 2012 | Developer Blog | 0 comments

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

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more