Giter VIP home page Giter VIP logo

myobjc-extension's Introduction

My Objective-C Extension

このフレームワークには、Objective-Cにはない機能をCategoryを使用して拡張をします。

拡張をしている Object と内容一覧

NSArray

  • - (NSArray*) map:(NSArrayMapBlock)mapblock; Map 関数を使用する(Mac OS 10.6以上/iOS4.0以上)
  • - (NSObject*) reduce:(NSArrayReduceBlock)reduceblock; Reduce 関数を使用する(Mac OS 10.6以上/iOS4.0以上)
  • - (id) getRandomObject; 配列にある任意のオブジェクトを、ランダムに返します。

Map Example

#import <OExtension.h>
#define N(n) [NSNumber numberWithInt:(n)]
…
NSArray* arr = [NSArray arrayWithObject:N(1),N(2),N(3),nil];
NSNumber* sum = [arr map:^(NSObject*a){
	NSObject* result = nil;
	result = [NSNumber numberWithInt:[(NSNumber*)obj intValue]+1];
	return obj;
}];

Reduce Example

#import <OExtension.h>
#define N(n) [NSNumber numberWithInt:(n)]
…
NSArray* arr = [NSArray arrayWithObject:N(1),N(2),N(3),nil];
NSNumber* sum = [arr reduce:^(NSObject*a, NSObject*b){
	NSObject* obj = (NSObject*)[NSNumber numberWithInt:
		[(NSNumber*)a intValue] + [(NSNumber*)b intValue]];
	return obj;
}];

NSData

  • - (NSString*)md5HexString データのMD5ハッシュ値を返します。
  • - (NSString*)sha256HexString; データのSHA256ハッシュ値を返します。
  • - (NSString*)sha512HexString; データのSHA512ハッシュ値を返します。

NSDate

  • +(NSDate*)dateFromRFC1123:(NSString*)value_; RFC1123フォーマットの日付をNSDate型にします。
  • -(NSString*)rfc1123String; NSDateオブジェクトをRFC1123フォーマットのNSString型にします。

NSDictionary

  • - (NSData*) dictionaryForQueryData; HTTPのQuery文字列に変換します。
  • - (NSString*)xmlDescription; NSDictionaryをplistのXMLにして返します。
  • + (NSDictionary*) dictionaryWithXMLFile:(NSString*)path; plistで整形されているXMLファイルを読み込み、NSDictionary型にします。
  • + (NSDictionary*) dictionaryWithFile:(NSString*)path; plistないしはxmlファイルを読み込みます。

NSString

  • + (NSString*)strReplace:(NSString*)source replace:(NSString*)r to:(NSString*)t; 文字列を置換します
  • + (NSString*)stringFromRandomWithLength:(NSInteger)length; 指定した長さのランダム文字列を生成します。
  • + (NSString*) stringWithRandomUUID; UUID4 の文字列を作成します。
  • - (BOOL) equalToString:(NSString*)str; 文字列を厳密な比較をします。
  • - (BOOL) isNoneLiteralEqualToString:(NSString*)str; 大文字小文字を区別せずに比較します。
  • - (NSString*) abstructPathFromBundle:(NSBundle*)bundle; ファイル名から絶対パスを作ります
  • - (NSString*) lastNameComponent; 拡張子を消したファイル名を取得します。
  • - (NSString*) urlEncoding; URL Encode をします。

NSRecursiveLock

  • - (void) runLockBlock:(void(^)(void))block; block をロックした状態で実行します

runLockBlock: Sample

#import <OExtension.h>
static NSRecursiveLock* globalLock = [[NSRecursiveLock alloc] init];
static NSMutableString* infoLog    = [[NSMutableString alloc] init];
#define info(__FORMAT__, ...) [globalLock runLockBlock:^{\
	[infoLog appendFormat:(@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]; \
}]

// some a code...
if ([args length])
	info(@"infomation: %@ is found", args);

LICENSE

BSD-style open source license

Copyright (c) 2010,2011 a.yasui [email protected] All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

myobjc-extension's People

Contributors

a-yasui avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.