• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Objective-C
  • License
    Other
  • Created about 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Foundation/Cocoa/UIKit extension kit. Reference document:

@mainpage FoundationExtension

Build Status

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

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];

@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 use <objc/runtime.h>

FoundationExtension

[obj performSelector:sel withObject:o1 withObject:o2 withObject:o3];

@see @ref NSObject(ObjCRuntime)

Get NSData from post request

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];

@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

Foundation

NSMutableArray *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

Foundation

NSString *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

Foundation

int 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

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];

@see @ref NSData(CommonCrypto)

plist dictionary decode from HTTP post request

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];

@see @ref NSMutableURLRequest(HTTPMethod) @see @ref NSData(NSURLRequest) @see @ref NSDictionary(NSData)

UIColor from HTML color code

UIKitExtension

UIColor *color = [UIColor colorWithHTMLExpression:@"#f0f0f0"];

@see @ref UIColor(HTMLColor)

Change implementation to new one

FoundationExtension

[class methodObjectForSelector:@selector(method1)].implementation
  = [class methodObjectForSelector:@selector(method2)].implementation;
// now [obj method1] equals [obj method2]

@see NSAMethod

Retrieve accessibility for private variable.

FoundationExtension

@interface Secret: NSObject { @private id _attr; } @end // #1 remember the '_attr'
// Hack the Secret!
@interface Secret (Accessor)
@property
    (nonatomic, retain) id attr; // #2 remember the 'attr'
@end
@implementation Secret (Accessor)
NSAPropertyGetter(attr, "_attr") // #2, #1 to create getter
NSAPropertyRetainSetter(setAttr, "_attr") // #2, #1 to create getter
@end

@see NSObject(ObjCRuntime)

For more

See the document! [http://youknowone.github.com/FoundationExtension] (http://youknowone.github.com/FoundationExtension)

More Repositories

1

UI7Kit

Backport flat-style UIKit from iOS7 to iOS5+
Objective-C
1,667
star
2

ring

Python cache interface with clean API and built-in memcache & redis + asyncio support.
Python
479
star
3

VisualJSON

JSON pretty-viewer for OS X.
Objective-C
302
star
4

itunes-iap

Apple iTunes In-app purchase verification tool
Python
133
star
5

UIKitResources

This repository includes UIKit resources of Apple iOS7.
104
star
6

methodtools

Expand functools features(lru_cache) to class - methods, classmethods, staticmethods and even for (unofficial) hybrid methods.
Python
75
star
7

apple-sys

The auto-managed -sys crate for Apple platforms using bindgen directly from build environment
Rust
53
star
8

Say

Convert text to audiable speech. Play it or save it to audio file.
Swift
26
star
9

QRQR

QRQR, the world simplest QR code decoder for iOS
Objective-C
24
star
10

hangul-romanize

Hangul romanization library for academy - ꡭ립ꡭ어원 ν•™μˆ  ν‘œκΈ°λ²•
Python
23
star
11

slairck

Slack as an IRC client
Python
19
star
12

rust-xcode-langspec

xcode langspec for rust
Shell
17
star
13

sqlite3-objc

Sqlite3 Objective-C wrapper
Objective-C
16
star
14

cdebug

Debug mode log/assertion for C/Objective-C in a file
Objective-C
15
star
15

writedown

Markdown editor with realtime preview for OS X
PHP
13
star
16

baembal

Boost ast.parse with RustPython-powered parser technology
Python
12
star
17

xcode-libcxx

The missing libc++ headers in Xcode9 (Sigh).
C++
10
star
18

result-like

Rust
9
star
19

gitstat

Simple, static gitstat generator.
HTML
9
star
20

prettyexc

Make your python exception human readable in easy way.
Python
8
star
21

isNamyang

Swift
8
star
22

python-deadlib

Python dead batteries. See PEP 594.
Python
8
star
23

libintl-alternative

Replace libintl part of gettext runtime with NSBundle localizedString: for OSX/iOS.
C
8
star
24

the-swift-programming-language-ko

7
star
25

coinwraps

Python
7
star
26

wirerope

Python
6
star
27

ObjectXML

Simple XML object model for Objective-C from NSXMLParser
Objective-C
6
star
28

brotli-file

File interface for brotli
Python
5
star
29

DropYourIcons

Create icons for App Store in a minutes / for OS X
Objective-C
5
star
30

ingress-slack

Ingress Slack bot scripts
Python
5
star
31

SocialAccountKit

Social.framework + Account.framework boilerplate kit for iOS6+
Objective-C
5
star
32

cacheobj

Python cache interface with object-property interface.
Python
4
star
33

nonghyeop

λ†ν˜‘ μ„œλ²„ μ²΄ν—˜νŒ
4
star
34

3finalnoshift

μ„Έλ²Œμ‹ μ΅œμ’… μˆœμ•„λž˜ (κ°€μΉ­) 자판의 λ‚ κ°œμ…‹ μ„€μ • 파일
4
star
35

hangulize-ios

iOS frontend for http://hangulize.org
Swift
4
star
36

youknowone

4
star
37

koreanbot

An IRC-bot on the easyirc
Python
4
star
38

rust-objc-abandoned

Rust
3
star
39

easyirc

Easy IRC is an IRC toolkit to develop IRC client or bot, especially for Python/IRC beginner.
Python
3
star
40

AdMobHelper

Shortcut function for AdMob
Objective-C
3
star
41

slackcode

General purpose slack outhook bot
Python
3
star
42

macciv5-ko

λ§₯용 λ¬Έλͺ…5λ₯Ό μœ„ν•œ ν•œκ΅­μ–΄ 팩 μ„€μΉ˜
Shell
3
star
43

hangeul

Input method library for Hangeul
C++
3
star
44

gcc-arm-mac

Makefile
2
star
45

memvec

Rust
2
star
46

text-ko

2
star
47

RapidForm

RapidForm is a form generator for PHP working with only a file.
PHP
2
star
48

dinomic

Python
2
star
49

syn-ext

Human-friendly an editable extension for https://crates.io/crates/syn
Rust
2
star
50

rust-divide

Rust
1
star
51

JoseonCamera

뭐든 λΆν•œμ‚°μœΌλ‘œ λ§Œλ“€μ–΄μ£ΌλŠ” μœ μš©ν•œ iOS μ•±
Objective-C
1
star
52

apple-sys-prebuilt

Rust
1
star
53

codejam2019

Python
1
star
54

SayKit

Convert text to audible speech
Swift
1
star
55

macmsn-ko

λ§₯ OS X 용 Microsoft Messenger 의 ν•œκ΅­μ–΄ 지역화 λ¦¬μ†ŒμŠ€
JavaScript
1
star
56

BalloonChat

Balloon chat view for Cocoa
Objective-C
1
star
57

transtool

transtool is dictionary-rewritting-base general-purpose translation copilier.
Python
1
star
58

rrcounter

C++ Round Robin Counter
C++
1
star
59

aheui-rust

Aheui interpreter in Rust
Rust
1
star
60

zxing

zxing unofficial mirror by need (http://zxing.googlecode.com/svn/trunk/)
Java
1
star
61

Digistatic

https://www.codeproject.com/Articles/307/Static-LED-control-CDigiStatic
C++
1
star
62

CaulySDK

Cauly SDK 3 with helper
Objective-C
1
star
63

redistruct

Human-friendly structured redis API wrapper.
Python
1
star
64

github-profile

Github profile generator by manually written data
CSS
1
star
65

xcodepkgtool

Simple .pkg deployment script for xcode OS X project
Shell
1
star
66

DictionaryWrapper

Objective-C
1
star
67

hangeul-rust

hangeul manipulation module for rust
Rust
1
star
68

IdealCocoa

Tiny extensions of Cocoa library
Objective-C
1
star
69

parrotim

Parrot is an Input Method for Mac OS X which speech your typing
Objective-C
1
star
70

redis-pubsub-helper

Redis pubsub non-blocking interface (With a thread).
Python
1
star