• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 9 years ago

Reviews

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

Repository Details

Collection of helpful categories for base obj-c classes

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