Need help with APUtils?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

andrei512
125 Stars 15 Forks MIT License 129 Commits 0 Opened issues

Description

Collection of helpful categories for base obj-c classes

Services available

!
?

Need anything else?

Contributors list

# 410,073
Objecti...
Shell
C
57 commits
# 668
Objecti...
Swift
carthag...
watchos
45 commits
# 635,461
Objecti...
Shell
C
21 commits
# 9,667
autohot...
ahk
bitwise...
Nette
1 commit

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.