@mainpage
This library includes small Cocoa/UIKit extensions. This library does not includes high-level data structure, algorithm or frameworks, but collection of code snippets.
- Many common snippets in a method call.
- Looks like native foundation methods - It follows Apple Coding Guideline and Foundation naming convention.
See document on [Github] (http://youknowone.github.com/FoundationExtension)
git clone git://github.com/youknowone/FoundationExtension.git
cd FoundationExtension
git submodule update --init
- Compiled library
- Build project
- Add FoundationExtension or UIKitExtension target as dependency
- Directy source
- Add files what you need to your project
- CocoaPod
- Visit and follow http://cocoapods.org/
If your compiler is gcc or old clang, add '-force_load' to static library.
Make your code short! Do not allow evil objc to make your code verbose. This library includes many shortcuts for common work.
Foundation
NSString *URLString = [NSSring stringWithFormat:@"http://"HOST_URL"/api/%@", key];
NSURL *URL = [NSURL URLWithString:URLString];
FoundationExtension
NSURL *URL = [[@"http://"HOST_URL"/api/%@" format:key] URL];
Foundation
- No way. You should use <objc/runtime.h>
FoundationExtension
[obj performSelector:sel withObject:o1 withObject:o2 withObject:o3];
Foundation
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:@"field1=value1"];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
FoundationExtension
NSData *data = [NSData dataWithContentsOfURL:URL postBody:@{@"field1":@"value1"} encoding:NSUTF8StringEncoding];
Foundation
- No way.
FoundationExtension
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMultiPartFormPostBody:@{@"filename":data} encoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithContentOfURLRequest:request];
Foundation
NSString *className = [NSString stringWithUTF8String:class_getName(obj.class)];
FoundationExtension
NSString *className = obj.classObject.name;
Foundation
- No way.
FoundationExtension
NSString *base64String = [data base64String];
Foundation
int value;
sscanf(string.UTF8String, "%x", &value);
FoundationExtension
NSInteger value = [string hexadecimalValue];
Foundation
- Why should foundation has this?
FoundationExtension
NSInteger value = [string integetValueBase:12];
Foundation
unsigned char hashedChars[CC_MD5_DIGEST_LENGTH];
CC_MD5([data bytes], (CC_LONG)[self length], hashedChars);
NSMutableString *result = [[NSMutableString alloc] init];
for ( int i = 0; i<CC_MD5_DIGEST_LENGTH; i++ )
[result appendFormat:@"%02x", *(hashedChars+i)];
FoundationExtension
NSString *result = [data digestStringByMD5];
Foundation
- Get data from NSURLRequest. Ehh.. so what can I do now? (Use NSPropertyListSerialization)
FoundationExtension
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPPostBody:@{@"key1":@"value1"} encoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithContentOfURLRequest:request];
NSDictionary *dictionary = [NSDictionary dictionaryWithData:data];
FoundationExtension
UIColor *color = [UIColor colorWithHTMLExpression:@"#f0f0f0"];
FoundationExtension
NSAClass *c = obj.classObject;
[c methodObjectForSelector:@selector(method1)].implementation
= [c methodObjectForSelector:@selector(method2)].implementation;
// now [obj method1] is [obj method2]
See the document! [http://youknowone.github.com/FoundationExtension] (http://youknowone.github.com/FoundationExtension)