Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youknowone/FoundationExtension
Foundation/Cocoa/UIKit extension kit. Reference document:
https://github.com/youknowone/FoundationExtension
cocoapods extension objective-c shortcuts snippets
Last synced: 3 months ago
JSON representation
Foundation/Cocoa/UIKit extension kit. Reference document:
- Host: GitHub
- URL: https://github.com/youknowone/FoundationExtension
- Owner: youknowone
- License: other
- Created: 2012-10-16T14:31:33.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2019-11-03T11:01:10.000Z (about 5 years ago)
- Last Synced: 2024-07-11T14:10:20.203Z (4 months ago)
- Topics: cocoapods, extension, objective-c, shortcuts, snippets
- Language: Objective-C
- Homepage: http://youknowone.github.io/FoundationExtension
- Size: 5.8 MB
- Stars: 121
- Watchers: 10
- Forks: 22
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
@mainpage FoundationExtension
[![Build Status](https://travis-ci.org/youknowone/FoundationExtension.svg?branch=master)](https://travis-ci.org/youknowone/FoundationExtension)
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)
# How to use
* Compiled library
1. Build project
2. Add FoundationExtension or UIKitExtension target as dependency
* Directy source
1. Add files what you need to your project
* CocoaPod ~> 1.7.5
1. Visit and follow http://cocoapods.org/If your compiler is gcc or old clang, add '-force\_load' to static library.
# Download for editing
git clone git://github.com/youknowone/FoundationExtension.git
cd FoundationExtension
git submodule update --init# Why useful
Make your code short! Do not allow evil objc to make your code verbose.
This library includes many shortcuts for common work.## NSData from URL
FoundationNSString *URLString = [NSSring stringWithFormat:@"http://"HOST_URL"/api/%@", key];
NSURL *URL = [NSURL URLWithString:URLString];FoundationExtension
NSURL *URL = [[@"http://"HOST_URL"/api/%@" format:key] URL];
@see @ref NSString(Shortcuts)
@see @ref NSString(NSURL)## iPhone MAC Address
Foundation
* No way.FoundationExtension
[[UIDevice currentDevice] MACAddress]
@see @ref UIDevice(Shortcuts)
## performSelector, with 3 object
Foundation
* No way. You should useFoundationExtension
[obj performSelector:sel withObject:o1 withObject:o2 withObject:o3];
@see @ref NSObject(ObjCRuntime)
## Get NSData from post request
FoundationNSMutableURLRequest *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];
@see @ref NSData(NSURLRequest)
## Get NSData from Multipart Form POST
Foundation
* No way.FoundationExtension
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMultiPartFormPostBody:@{@"filename":data} encoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithContentOfURLRequest:request];@see NSURLRequestAdditions.h
## Truncate strings in array
FoundationNSMutableArray *newArray = [NSMutableArray array];
for (NSString *s in array) {
[newArray addObject:[s substringToIndex:20]];
}FoundationExtension NSArray
NSArray *newArray = [array arrayByMappingOperation:^(NSString *obj){ [obj substringToIndex:20]; }];
FoundationExtension NSMutableArray
[array map::^(NSString *obj){ [obj substringToIndex:20]; }];
@see @ref Map/Filter/Reduce
@see NSAFunctional.h## Get a class name
FoundationNSString *className = [NSString stringWithUTF8String:class_getName(obj.class)];
FoundationExtension
NSString *className = obj.class.name;
@see @ref NSObject(ObjCRuntime)
@see @ref NSObject(ObjCRuntimeClass)## Get hexadecimal value from base 16 string
Foundationint value;
sscanf(string.UTF8String, "%x", &value);FoundationExtension
NSInteger value = [string hexadecimalValue];
@see @ref NSData(Serialization)
## How about base 12 string?
Foundation
* Why should foundation has this?FoundationExtension
NSInteger value = [string integerValueBase:12];
@see @ref NSString(Evaluation)
## md5 hash
Foundationunsigned 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