APUtils

by andrei512

andrei512 / APUtils

Collection of helpful categories for base obj-c classes

125 Stars 15 Forks Last release: almost 5 years ago (2.1.5) MIT License 129 Commits 14 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

APUtils 2.0 alpha Flattr this git repo

A collection of helpful categories for base obj-c classes and snippets I collected in four years of iOS development.

Install using 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;

Many thanks to:

Bitdeli Badge

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.