Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabriel/GHKit
Utilities and categories for Objective-C
https://github.com/gabriel/GHKit
Last synced: 3 months ago
JSON representation
Utilities and categories for Objective-C
- Host: GitHub
- URL: https://github.com/gabriel/GHKit
- Owner: gabriel
- License: mit
- Created: 2008-08-07T17:04:25.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2016-03-22T20:24:30.000Z (almost 9 years ago)
- Last Synced: 2024-10-31T15:51:10.306Z (3 months ago)
- Language: Objective-C
- Homepage:
- Size: 12.2 MB
- Stars: 260
- Watchers: 21
- Forks: 40
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - GHKit - Utilities and categories for Objective-C (etc)
- awesome - GHKit - Utilities and categories for Objective-C (etc)
README
# GHKit
The GHKit framework is a set of extensions and utilities for Mac OS X and iOS.
## Podfile
pod "GHKit"
## Usage
GHKit defines various categories and general purpose utilities.
For example, parsing date strings, date math, string manipulations, URL dictionary formatting, etc. Some examples are below.
All categories are namespaced with gh_ to avoid conflicts.
***Import:***
```objc
#import
```***Dates:***
`GHNSDate+Formatters.h`: Date parsers, formatting and formatters for ISO8601, RFC822, HTTP (RFC1123, RFC850, asctime) and since epoch.
```objc
NSDate *date = [NSDate gh_parseISO8601:@"2010-10-07T04:25Z"];
NSString *dateString = [date gh_formatHTTP]; // Formatted like: Sun, 06 Nov 1994 08:49:37 GMT"
NSDate *date = [NSDate gh_parseTimeSinceEpoch:@(1234567890)];
````GHNSDate+Utils.h`: For time ago in words and date component arithmentic (adding days), tomorrow, yesterday, and more.
```objc
NSDate *date = [NSDate date];
[date gh_isToday]; // YES
[[date gh_yesterday] gh_isToday]; // NOdate = [date gh_addDays:-1];
[date gh_wasYesterday]; // YES[date gh_timeAgo:NO]; // @"1 day"
```***Arrays:***
`GHNSArray+Utils.h`: Random object, safe object at index, uniq, compact
```objc
[@[@(1), @(2), @(3)] gh_random]; // Random object
[@[@(1), @(1), @(3)] gh_uniq]; // @[@(1), @(3)]
[@[] gh_objectAtIndex:0]; // nil (Safe objectAtIndex)
[@[@(1), NSNull.null] gh_compact]; // @[@(1)]
```***Dictionaries:***
`GHDictionary+Utils.h`:
```objc
NSDictionary *dict = @{@"key1": @(2), @"key2": @(3.1), @"key3": @YES};
NSString *JSONString = [dict gh_toJSON:NSJSONWritingPrettyPrinted error:nil];
```***Strings:***
`GHNSString+Utils.h`: Stripping, reversing, counting and more.
```objc
[NSString gh_isBlank:@" "]; // YES
[NSString gh_isBlank:nil]; // YES
[@" some text " gh_strip]; // @"some text"
[@" " gh_isPresent]; // NO
[@"abc" gh_isPresent]; // YES
[@" " gh_present]; // nil
[@"some text" gh_present]; // @"some text"[@"abc" gh_reverse]; // @"cba"
[@"ababababcde" gh_count:@"ab"]; // 4 (@"ab" appears 4 times)
[NSString gh_localizedStringForTimeInterval:30]; // "half a minute"
[NSString gh_abbreviatedStringForTimeInterval:30]; // @"30s"[@"WWW.test.com" gh_startsWith:@"www." options:NSCaseInsensitiveSearch]; // YES
[@"foo:bar" gh_lastSplitWithString:@":" options:NSCaseInsensitiveSearch]; // @"bar"[@"e̊gâds" gh_characters]; // @[@"e̊", @"g", @"â", @"d", @"s"];
```***URLs:***
`GHNSURL+Utils.h`: Encoding, escaping, parsing, splitting out or sorting query params, and more.
```objc
NSDictionary *dict = [@"c=d&a=b" gh_queryStringToDictionary]; // Dictionary with a => b, c => d
[NSDictionary gh_dictionaryToQueryString:dict sort:YES]; // @"a=b&c=d"
```***Colors:***
`GHUIColor+Utils.h`: Colors from hex, color space changes, darken.
```objc
UIColor *color = GHUIColorFromRGB(0xBC1128);
GH_HSV hsvColor = [color gh_hsv];
UIColor *darkenedColor = [color gh_darkenColor:0.1]; // Darken 10%
```And more...