This file contains 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
let maximumNumberOfLoginAttempts = 10 | |
var currentLoginAttempt = 0 | |
var x = 0.0, y = 0.0, z = 0.0 | |
var welcomeMessage: String | |
var red, green, blue: Double | |
let π = 3.14159 | |
let 你好 = "你好世界" | |
let 🐶🐮 = "dogcow" | |
print(friendlyWelcome) |
This file contains 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
// How to do lots of cool things with NSArray.Inspired by NSHipster and WWDC 2013 Session 228 - "Hidden Gems in Cocoa and Cocoa Touch" | |
NSArray *albums = @[[Album albumWithName:@"Random Access Memories" price:9.99f], | |
[Album albumWithName:@"Clarity" price:6.99f], | |
[Album albumWithName:@"Weekend in America" price:7.99f], | |
[Album albumWithName:@"Weekend in America" price:7.90f], | |
[Album albumWithName:@"Bangarang EP" price:2.99f]]; | |
// Reversing an Array |
This file contains 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
#define XGRunOnMainThread _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ | |
if (![NSThread isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self performSelector:_cmd]; }); return; }; |
This file contains 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
void dispatch_once_on_main_thread(dispatch_once_t *predicate, | |
dispatch_block_t block) { | |
if ([NSThread isMainThread]) { | |
dispatch_once(predicate, block); | |
} else { | |
if (DISPATCH_EXPECT(*predicate == 0L, NO)) { | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
dispatch_once(predicate, block); | |
}); | |
} |
This file contains 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
NSLog(@"%@",[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]); |
This file contains 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
@interface NSArray (EnumExtensions) | |
- (NSString*) stringWithEnum: (NSUInteger) enumVal; | |
- (NSUInteger) enumFromString: (NSString*) strVal default: (NSUInteger) def; | |
- (NSUInteger) enumFromString: (NSString*) strVal; | |
@end | |
@implementation NSArray (EnumExtensions) |
This file contains 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
As a local variable: | |
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...}; | |
As a property: | |
@property (nonatomic, copy) returnType (^blockName)(parameterTypes); | |
As a method parameter: | |
- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName; | |
As an argument to a method call: |