Created
March 31, 2013 01:26
-
-
Save brendanjerwin/5279096 to your computer and use it in GitHub Desktop.
How are my Obj-C idioms?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // main.m | |
| // Juice | |
| // | |
| // Created by Brendan Erwin on 3/26/13. | |
| // Copyright (c) 2013 Brendan Erwin. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| #import "ObjectiveSugar.h" | |
| const int BJESecondsInADay = 60 * 60 * 24; | |
| @implementation NSDate (BJESugar) | |
| + (NSDate *)tomorrow { | |
| return [[NSDate date] dateByAddingTimeInterval:BJESecondsInADay]; | |
| } | |
| @end | |
| int main(int argc, const char *argv[]) { | |
| @autoreleasepool { | |
| NSDate *today = [NSDate date]; | |
| NSDate *tomorrow = [NSDate tomorrow]; | |
| NSDateFormatter *outputFormater = [NSDateFormatter new]; | |
| outputFormater.dateStyle = NSDateFormatterFullStyle; | |
| outputFormater.timeStyle = NSDateFormatterLongStyle; | |
| NSDateFormatter *inputFormatter = [NSDateFormatter new]; | |
| inputFormatter.dateStyle = NSDateFormatterShortStyle; | |
| NSDate *inputDate = [inputFormatter dateFromString:@"07/16/1976"]; | |
| NSLog(@"Today is %@", [outputFormater stringFromDate:today]); | |
| NSLog(@"Tomorrow is %@", [outputFormater stringFromDate:tomorrow]); | |
| NSLog(@"Input date is %@", [outputFormater stringFromDate:inputDate]); | |
| NSArray *names = @[@"Brendan", @"Kirsten", @"Christian", @"Sean", @"Abigail"]; | |
| [names enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
| NSLog(@"Name is: %@", obj); | |
| }]; | |
| NSLog(@"Name at 1: %@", names[1]); | |
| NSDictionary *teams = @{@"Carbon": @"James, Alan, Randall, Kenny", | |
| @"Cobalt": @"Ricardo, Steve, Kene, Chris, Mark"}; | |
| [teams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
| NSLog(@"Team: %@ - %@", key, obj); | |
| }]; | |
| NSSet *reasons = [NSSet setWithArray:@[@"because", @"I said so", @"because"]]; | |
| [reasons enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { | |
| NSLog(@"Reason: %@", obj); | |
| }]; | |
| NSString *boxTest = @("test"); | |
| NSLog(@"Boxed %@", boxTest); | |
| [@3 times :^{ | |
| NSLog(@"Hey"); | |
| }]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment