Skip to content

Instantly share code, notes, and snippets.

@Gi-lo
Gi-lo / gist:6536397
Last active December 22, 2015 21:49
Implicit Cast to Bool
// Just a string
NSString *string = @"Trololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololol";
// Not so clever implicit BOOL cast
BOOL hasText = [string length]; // Just add "> 0" to fix it btw.
// Sure it has some text! ... eh wait what
NSLog(@"String has some text: %@", hasText ? @"YES" : @"NO");
// And to have some reference to the blog post ... (http://blog.bignerdranch.com/564-bools-sharp-corners/)
@Gi-lo
Gi-lo / gist:4279932
Created December 13, 2012 21:11
Easily create GET NSURLs in Objective-C. (Used in https://github.com/Gi-lo/GCXHTTPOperation )
- (NSURL *)URLWithString:(NSString *)string andQueryValuesForKeys:(NSString *)value, ... {
if (!value) {
return [NSURL URLWithString:string];
}
NSMutableString *queryString = [NSMutableString string];
NSString *argument = nil;
NSUInteger argumentCount = 0;
va_list argumentList;
@Gi-lo
Gi-lo / gist:4174484
Created November 30, 2012 08:18
iPad/iPhone specific code
On_iPhone(^{
// Some iPhone only code
});
On_iPad(^{
// Some iPad only code
});
or: