APUtils 2.1.5

APUtils 2.1.5

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新版本2015年10月

Bogdan Poplauschiandrei512 维护。



APUtils 2.1.5

  • 作者
  • andrei512

APUtils 2.0 alpha Flattr this git repo

这是一组我收集了四年 iOS 开发中的基础 Objective-C 类别和片段的实用类别。

使用 Cocoapods 安装

pod 'APUtils'

APUtils.h

+ (BOOL)canMakePhoneCalls;

// one liner that dismisses the keyboard
+ (void)findAndResignFirstReponder;

// measures the time a block takes to execute
+ (void)benchmark:(void(^)(void))block name:(NSString *)name;
+ (void)benchmark:(void(^)(void))block;

NSArray

- (NSMutableArray *)filterWithBlock:(APBoolBlock)block;

- (NSMutableArray *)mapWithBlock:(ObjectBlock)block;

- (NSMutableArray *)mapWithSelector:(SEL)selector;

// uses NSObject+APUtils to create objects from a JSON array
- (NSMutableArray *)mapToClass:(Class)objectClass;

// load an array from a plist located in the main bundle
+ (NSArray *)arrayFromPlistNamed:(NSString *)name;

// example: @[@1, @2, @3].join(@", ") -> @"1, 2, 3"
- (APStringStringBlock)join;

NSDictionary

// combines two dictionaries 
- (NSMutableDictionary *)merge:(NSDictionary *)dict;

NSNumber

- (NSString *)formatedString;

- (NSString *)formatedStringWithCurrency:(NSString *)currency;

NSObject

// Exameple for - (id)loadFrom:(id)data
//
// @interface User
//
// @property (nonatomic, retain) NSString *firstName;
// @property (nonatomic, retain) NSString *lastName;
//
// @property (nonatomic, retain) NSNumber *age;
//
// @end
//
// ...
//
// NSDictionary *info = @{
//                        @"firstName" : @"Andrei",
//                        @"last_name" : @"Puni",
//                        @"age" : @22,
// };
//
// User *user = [[User new] fromJson:info];
//
// now user.firstName is @"Andrei", user.lastName is @"Puni" and user.age is @22

- (instancetype)fromJson:(id)data;

// [user asJson] wil return 
//
// @{
//    @"firstName" : @"Andrei",
//    @"lastName" : @"Puni",
//    @"age" : @22,
// }

- (NSDictionary *)asUnserscoredJson;

// [user asUnserscoredJson] wil return 
//
// @{
//      @"first_name" : @"Andrei",
//      @"last_name" : @"Puni",
//      @"age" : @22,
// }

- (NSDictionary *)asUnserscoredJson;

// user could have been created like so
// User *user = [User createFrom:info];

+ (id)createFrom:(id)data;

- (NSString *)className;

NSString

// [@"FooBar stringByRemovingSuffix:@"Bar"] -> @"Foo"
- (NSString *)stringByRemovingSuffix:(NSString *)suffix;

- (BOOL)containsString:(NSString *)substring;
- (BOOL)containsString:(NSString *)substring caseSensitive:(BOOL)sensitive;

// test is matches a regexp 
// ! there a some predefined patters for
// kNumberRegex - floats
// kIntegerRegex - integers
// kEmailRegex - emails

- (BOOL)matches:(NSString *)pattern;

- (NSString *)stringByEscapingPercents;
- (NSString *)stringByUnscapingPercents;

- (NSString *)stringByBase64EncodingString;
- (NSString *)stringByBase64DecodingString;
- (NSData   *)dataByBase64DecodingString;

- (NSString *)HMAC_SHA1SignatureWithKey:(NSString *)signingKey;
+ (NSString *)randomStringWithLength:(NSUInteger)length;

- (NSData   *)UTF8Data;

NSUserDefaults

// sets a value in NSUserDefaults syncronizes
+ (BOOL)setUserValue:(id)value forKey:(id)key;

// convenience method for geting the value for a key from NSUserDefaults
+ (id)valueForKey:(NSString *)key;

UITextField

- (void)persistAs:(NSString *)identifier;

+ (void)clearStoredTexts;
+ (void)saveText:(NSString *)text forIdentifier:(NSString *)identifier;

许多感谢

Bitdeli Badge