Created
October 7, 2013 08:08
-
-
Save wolfhechel/6864182 to your computer and use it in GitHub Desktop.
Butloads of Categories
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
// | |
// NSArray+firstObject.h | |
// | |
// Created by Pontus Carlsson on 2013-10-02. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSArray (firstObject) | |
- (id)firstObject; | |
@end |
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
// | |
// NSArray+firstObject.m | |
// | |
// Created by Pontus Carlsson on 2013-10-02. | |
// | |
#import "NSArray+firstObject.h" | |
@implementation NSArray (firstObject) | |
- (id)firstObject | |
{ | |
id object = nil; | |
if (self.count > 0) { | |
object = [self objectAtIndex:0]; | |
} | |
return object; | |
} | |
@end |
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
// | |
// NSString+URLEncoding.h | |
// | |
// Created by Pontus Carlsson on 2013-09-25. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSString (URLEncoding) | |
- (NSString *)URLEncode; | |
- (NSString *)URLEncodeWithEncoding:(NSStringEncoding)encoding; | |
@end |
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
// | |
// NSString+URLEncoding.m | |
// | |
// Created by Pontus Carlsson on 2013-09-25. | |
// | |
#import "NSString+URLEncoding.h" | |
@implementation NSString (URLEncoding) | |
NSStringEncoding defaultEncoding = NSUTF8StringEncoding; | |
NSString *escapedCharacters = @"!*'\"();:@&=+$,/?%#[]% "; | |
- (NSString *)URLEncode | |
{ | |
return [self URLEncodeWithEncoding:defaultEncoding]; | |
} | |
- (NSString *)URLEncodeWithEncoding:(NSStringEncoding)encoding | |
{ | |
CFStringRef selfReference = (__bridge CFStringRef)self; | |
CFStringRef escapedCharactersReference = (__bridge CFStringRef)escapedCharacters; | |
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(nil, selfReference, nil, escapedCharactersReference, | |
CFStringConvertNSStringEncodingToEncoding(encoding))); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment