GHKit Reference
GHKit defines various categories and general purpose utilities.
For example, parsing date strings, generating time ago in words, generating SHA1-HMAC, MD5, or special invocation proxies.
Source: http://github.com/gabriel/gh-kit
View docs online: http://gabriel.github.com/gh-kit/
Install the docset:
- Open Xcode, Preferences and select the Downloads / Documentation tab.
- Select the plus icon (bottom left) and specify: http://gabriel.github.com/gh-kit/publish/me.rel.GHKit.atom
Use the framework:
#import <GHKit/GHKit.h>
Dates:
GHNSDate+Formatters.h: Date parsers, formatting and formatters for ISO8601, RFC822, HTTP (RFC1123, RFC850, asctime) and since epoch.
NSDate *date = [NSDate gh_parseISO8601:@"2010-10-07T04:25Z"]
NSString *dateString = [date gh_formatHTTP]; // Formatted like: Sun, 06 Nov 1994 08:49:37 GMT"
GHNSDate+Utils.h: For time ago in words and date component arithmentic (adding days), tomorrow, yesterday, and more.
NSDate *date = [NSDate date];
[date gh_isToday]; // YES
[[date gh_yesterday] gh_isToday]; // NO
date = [date gh_addDays:-1];
[date gh_wasYesterday]; // YES
[date gh_timeAgo:NO]; // @"1 day"
Strings:
GHNSString+Utils.h: Stripping, reversing, counting, UUID, MD5 and more.
[NSString gh_isBlank:@" "]; // YES
[NSString gh_isBlank:nil]; // YES
[@"abc" gh_reverse]; // @"cba"
[@" some text " gh_strip]; // @"some text"
URLs:
GHNSURL+Utils.h: Encoding, escaping, parsing, splitting out or sorting query params, and more.
NSDictionary *dict = [@"c=d&a=b" gh_queryStringToDictionary]; // Dictionary with a => b, c => d
[NSDictionary gh_dictionaryToQueryString:dict sort:YES]; // @"a=b&c=d"
Invocation:
GHNSObject+Invocation.h:
[[obj gh_proxyOnMainThread] myMethodWithInteger:4 string:@"string"]; // Call myMethod on main thread
[[array gh_proxyAfterDelay:2.0] insertObject:@"foo" atIndex:0]; // Inserts object after 2 second delay
SEL selector = @selector(bar:baz:);
[foo gh_argumentProxy:selector] arg:10 arg:YES];
Will call [foo bar:10 baz:YES]; (and not arg:arg: selector which doesn’t exist).
Files:
GHNSFileManager+Utils.h: File size, exists, generating temporary or unique file paths.
HMAC:
GHNSString+HMAC.h: SHA-1 HMAC
#import "GTMBase64.h"
["stringtosign" gh_HMACSHA1:@"secret" base64Encoder:[GTMBase64 class]];
Keychain:
Secret from keychain:
GHKeychainStore *keyChainStore = [[GHKeychainStore alloc] init];
NSError *error = nil;
NSString *secret = [keyChainStore secretFromKeychainForServiceName:@"MyApp" key:"password" error:&error];
if (!secret) NSLog(@"Error: %@", [error localizedDescription];
Save to keychain:
GHKeychainStore *keyChainStore = [[GHKeychainStore alloc] init];
NSError *error = nil;
BOOL saved = [keyChainStore saveToKeychainWithServiceName:@"MyApp" key:"password" secret:"12345" error:&error];
if (!saved) NSLog(@"Error: %@", [error localizedDescription];
And more…
Class References
Protocol References
Category References
- NSArray(GHUtils)
- NSAttributedString(GHUtils)
- NSBundle(GHUtils)
- NSData(GHBase64)
- NSDate(GHFormatters)
- NSDate(GHUtils)
- NSDictionary(GHNSNull)
- NSDictionary(GHUtils)
- NSError(GHUtils)
- NSFileManager(GHUtils)
- NSInvocation(GHUtils_GHKIT)
- NSMutableArray(GHUtils)
- NSMutableDictionary(GHUtils)
- NSNotificationCenter(GHUtils)
- NSNumber(GHUtils)
- NSObject(GHInvocation_GHKIT)
- NSObject(GHSwizzle)
- NSObject(GHUtils)
- NSString(GHHMAC)
- NSString(GHSymlinksAndAliases)
- NSString(GHTimeInterval)
- NSString(GHUIKitUtils)
- NSString(GHURL)
- NSString(GHUtils)
- NSString(GHXML)
- NSURL(GHUtils)
- NSUserDefaults(GHUtils)
- NSXMLElement(GHUtils)
- NSXMLNode(GHUtils)
- UIColor(GHUtils)