Home

Awesome

SeaseAssist

[![CI Status](http://img.shields.io/travis/Logan Sease/SeaseAssist.svg?style=flat)](https://travis-ci.org/Logan Sease/SeaseAssist) Version License Platform

Summary Info

This library is founded on the basis that commonly performed tasks, which take several lines of code to write should be encompased into simple methods, either using class extensions or services, that can be written in a single line of code. Thus reducing code redundancy and increasing code readibility.

In this package you will find the following:

Enjoy! Please feel free to fork and contribute to this repo!

Requirements

ios 7+

Installation

SeaseAssist is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SeaseAssist"

And import the following Header file

#import "SeaseAssist.h"

This pod will work if your project uses objective-c or Swift.

Author

Logan Sease, lsease@gmail.com

License

SeaseAssist is available under the MIT license. See the LICENSE file for more info.

Sorry, there is a lot here. I will do my best to try to keep this documentation readable.

UI CLASSES

CleanButton

A modern button with a nice clean rounded border, an empty background and some text

GlossyButton

A button with a gradient filled background matching the button's Tint Color

RoundedView

A View with slightly rounded corners and a thin border.

DatePickerTextField

Create a UITextField with a Date picker instead of a keyboard

ValuePickerTextField

A UITextField with a PickerView instead of a keyboard

MLTBadgeView

A badge that goes over any UIView. See UIView+Badge.h

[view.badge setBadgeValue:@"4"];

SERVICES

EventCounterService

A class to track events throughout the life of the app, or daily events

+(NSUInteger)addCountForEvent:(NSString*)event count:(NSInteger)add;
+(NSUInteger)addCountForEvent:(NSString*)event;
+(void)resetCountForEvent:(NSString*)event;
+(NSUInteger)checkCountForEvent:(NSString*)event;
+(NSUInteger)checkDailyEventCount:(NSString*)dailyEvent;
+(NSUInteger)addDailyEventCount:(NSString*)dailyEvent;
+(NSUInteger)addCountForDailyEvent:(NSString*)dailyEvent count:(NSInteger)count;

Sound Service

A service to play sounds and maintain a queue

+ (id)sharedService;
+(void)playSoundAtPath:(NSString*)path;
+(void)playSoundAtPath:(NSString*)path withVolume:(float)volume;
+(void)addSoundToQueueAtPath:(NSString*)path;
-(void)pauseQueue;
-(void)resumeQueue;
-(BOOL)isPlaying;

SpeechService

Simple Text to Speech with the Siri API

+ (id)sharedService;
+(BOOL)isSpeaking;
-(void)speakText:(NSString*)text;

Email Service

A simple Email interface to open an email view controller from anywhere.

-(void)emailTo:(NSArray*)emails withSubject:(NSString*)subject body:(NSString*)body attachments:(NSArray<MailServiceAttachment*>*)attachments fromVC:(UIViewController*)parent  andCompletion:(void(^)(BOOL success))handler;

Image Picker

A simple interface to show an image picker

@interface ImagePickerHelper 
-(void)selectImageFrom:(UIViewController*)source ofType:(UIImagePickerControllerSourceType)type andCompletion:(void(^)(UIImage* image))handler;

NETWORKING

HTTPRequest

A helper class to make http requests asynchronously in one line without the need for any 3rd party frameworks.

For a more robust Networking helper, see QwikHttp, and also QwikJson for json parsing.

+(void)jsonRequestToUrl:(NSString*)urlString withMethod:(NSString*)method withHeaders:(NSDictionary*)headers withParams:(NSDictionary*)params withHandler:(void (^)(NSString* response,NSError * error))handler;

+(void)httpRequestToUrl:(NSString*)urlString  withMethod:(NSString*)method withHeaders:(NSDictionary*)headers withParams:(NSDictionary*)params withHandler:(void (^)(NSString* response,NSError * error))handler;

+(NSString*)addParameters:(NSDictionary*)urlParams toUrl:(NSString*)url;

Reachability Helpers

Find our internet connection status.

@interface UIDevice (Reachability)
+(BOOL)connected;
@end

CLASS EXTENSIONS

Json Serialization and Deserialization

###NSDictionary

-(NSString*)toJsonString;
+(NSDictionary*)fromJsonString:(NSString*)json;

###NSArray

-(NSString*)toJsonString;
+(NSArray*)fromJsonString:(NSString*)json;

NSDate Helpers

-(NSDate*)beginningOfWeek;
-(NSDate*)endOfWeek;

-(NSDate*)beginningOfMonth;
-(NSDate*)endOfMonth;

-(NSDate*)beginningOfYear;
-(NSDate*)endOfYear;
-(NSDate*)dateWithCurrentYear;

-(NSString*)dateToStringWithFormat:(NSString*)format;

-(NSDate*)dateAtEndOfDay;
-(NSDate*)dateWithoutTime;
-(NSDate*)timeValue;
-(BOOL)isOnBeforeOrToday;
-(BOOL)isToday;
-(BOOL)isBeforeToday;

-(BOOL)isBetween:(NSDate*)startDate and:(NSDate*)endDate;
-(NSDate*)dateByAdvancingMonths:(NSInteger)monthCount;
-(BOOL)isAfterDate:(NSDate*)secondDate;
-(BOOL)isBeforeDate:(NSDate*)secondDate;

Date Helpers

public extension Date {
public func isSameDay(as date: Date?) -> Bool
public func nsdate() -> NSDate
public func isOnOrAfter(_ date: Date!) -> Bool
}

NSMutableArray Helpers

- (void)shuffle;

//wrap an array around a single object (make it the first object and then go to the end
//and start back at the beginning.
-(NSArray*)rotatedArrayAround:(NSInteger)index;
public extension Array {
public mutating func swap(from ind1: Int, to ind2: Int)
}

NSString Helpers

-(NSInteger)occurancesOfString:(NSString*)test;
-(BOOL)contains:(NSString *)string;
+(NSString*)empty;
- (NSInteger)indexOf: (char)character;
-(NSArray *)splitOnChar:(char)ch;
-(NSString *)substringFrom:(NSInteger)from to:(NSInteger)to;
-(NSString *)stringByStrippingWhitespace;
-(NSString*)initials; //Herby Hancock = HH
+(NSString*)displayString:(float)number; //1,200 = 1.2K
-(NSString*)generateRandom:(int)length;

NSString validation

-(BOOL)isValidEmail:(BOOL)laxValidation;
-(BOOL)isValidEmail;
-(BOOL)isDigitOfLength:(NSInteger)length;
-(BOOL)isBlank;
+(BOOL)isValidAlphanumbericChars:(NSString*)textString;

String Format Helpers

extension String {
public static func isEmpty(_ string: String?) -> Bool

public static func nonWhiteSpaceCharacterCount(_ string: String?) -> Int

public func upperCasedWords() -> String

public func capitalizingFirstLetter() -> String

public var isSingleEmoji: Bool { get }

public var containsEmoji: Bool { get }

public func camelCaseToTitleCase() -> String!

public func camelCaseToUnderscoreCase() -> String!

public func underscoreCaseToCamelCase() -> String!
}

String indexes and subscripting

extension String
{
public subscript(r: CountableClosedRange<Int>) -> String? { get }
}

Encryption Helpers

###NSData

-(NSData *) aesEncryptedDataWithKey:(NSData *) key;
-(NSString*)toBase64;
-(NSString*)base64Encoded
-(NSString*)base64Decoded

###NSString

- (NSData *) sha256;
- (NSString *) stringFromMD5;

//secure a string by adding Key Encryption and then Base 64 Encoding it.
- (NSString*)encryptWithKey:(NSString*)key;

NSThread Helpers

Run blocks in the main or background threads with ease

+(void)mainThread:(void (^)())main;
+(void)backgroundThread:(void (^)())background;
+(void)delay:(float)length code:(void (^)())function;

UIDevice: Unique Identifiers

Since apple now longer gives access to device level Identifier information, this is another way to get an Identifier based on a hash of the mac address

- (NSString *) uniqueDeviceIdentifier;
- (NSString *) uniqueGlobalDeviceIdentifier;

UIDevice system version

+(BOOL)versionGreaterThanOrEqual:(NSString*)version;

Keychain Helpers

Read and write to the keychain.

@interface UIDevice (Keychain)
+(void)write:(NSString*)value toKeychainWithKey:(NSString*)key appSpecific:(BOOL)appSpecific;
+(NSString*)readFromKeychainWithKey:(NSString*)key appSpecific:(BOOL)appSpecific;
@end

Alerts

###SAMBProgressHUD+Singleton An extension to SAMBProgressHUD to show a loading dialog singleton without needing to add it to your view or set it up.

+(void)showWithTitle:(NSString*)title;
+(void)hide;

###UIAlertController Show an alert controller with actions and get notified what action was chosen with a single line

+(void)showAlertWithTitle:(NSString*)title andMessage:(NSString*)message from:(UIViewController*)controller;
+(void)showDialogWithTitle:(NSString*)title andMessage:(NSString*)message from:(UIViewController*)controller andActions:(NSArray<NSString*>*)buttonTitles completionHandler:(void (^)(NSInteger selected))handler;
+(void)showTextEntryDialogWithTitle:(NSString*)title andMessage:(NSString*)message andPlaceHolder:(NSString*)holder from:(UIViewController*)controller completionHandler:(void (^)(NSString* text))handler;

###UIAlertView

+(void)showWithTitle:(NSString*)title andMessage:(NSString*)message;

###UILabel+Message Show a quick "Toast" on screen for a desired amount of time

+(void)showMessage:(NSString*)message ofSize:(float)fontSize ofColor:(UIColor*)color inView:(UIView*)view forDuration:(float)seconds;

Images

###UIImage Helpers

//Add a gassian Blur of the desired amount of pixels
-(UIImage*)blurredImage:(float)amount;


//Get an image from a file, but filled with a different fill color.
- (UIImage *)imageWithColor:(UIColor *)color;

//Scale an image.
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize;

//turn an image to greyscale
-(UIImage*) toGrayscale;

//capture an uiimage from a uiview
+(UIImage*)fromView:(UIView*)view;

Cache image and load from cache

+(void)cacheImage:(UIImage*)image forUrl:(NSString*)url;
+(NSString*)cacheFileNameFor:(NSString*)url;
+(UIImage*)cachedImageForUrl:(NSString*)url;
+(void)loadImageToCacheFrom:(NSString*)url;

###UIImageView Helpers Set an image from a URL and cache the image locally.

-(void)setImageUrl:(NSString*)urlString;

Round an image

-(void)round;
-(UIImage*)clippedToCircle;

Set an image from URL to a UIImage View with caching and a default

@interface UIImageView (Networking)
-(void)setImageFromUrl:(NSString*)url withDefault:(UIImage*)defaultImage andRounding:(BOOL)round;

Set an image from URL like above, but prefill with initials if no image is found

@interface UIImageView (Initials)
-(UILabel*)addInitialsPlaceholder:(NSString*)title circle:(BOOL)circle;
-(void)setImageFromUrl:(NSString*)urlString withPlaceholderString:(NSString*)holder withPlaceHolderImage:(UIImage*)image rounding:(BOOL)round;
-(void)setImageFromUrl:(NSString*)urlString withPlaceholderString:(NSString*)holder withPlaceHolderImage:(UIImage*)image rounding:(BOOL)round completionHandler:(BoolCompletionHandler)handler;

QR Code Generation

extension String
{
public func toQRCode() -> UIImage?
public func toHiDefQRCode() -> UIImage?
}

Animation

###UIView+Bounce Make your UI Feel alive and highlight important views by adding a playful bounce

-(void)bounceFrom:(float)from to:(float)to;
-(void)bounceTo:(float)scale;
-(void)bounce:(BOOL)repeat;
-(void)endBounce;

###UIView+MotionEffects Add cool motion effects that give your app depth by moving as you move your device

-(void)addMotionEffectsWithOffset:(float)offset;
-(void)addVerticalMotionEffectsWithOffset:(float)offset;
-(void)resizeFullScreenViewAndAddMotionEffectsWithOffset:(float)offset;
-(void)resizeHorizontallyAndAddMotionEffectsWithOffset:(float)offset;
+(void)addMotionEffectsTo:(NSArray*)views withOffset:(float)offset;

###UIView+AnimateShow animating hiding and showing of a view or a group of views

-(void)animateShow;
-(void)animateHide;
+(void)animateShow:(NSArray<UIView*>*)views;
+(void)animateHide:(NSArray<UIView*>*)views;
+(void)animateShow:(NSArray<UIView*>*)views withDelay:(float)delay;

View Appearance

###UIView

//round the corners 
-(void)round:(float)cornerRadius withBorderWidth:(float)width andColor:(UIColor*)color;
-(void)round;

//completely circle the view and optionally add a border.
-(void)circleWithColor:(UIColor*)color width:(float)width;
-(void)circle;

//add a visual effect view with a blur
-(UIVisualEffectView*)blur;

//adjust a frame
-(void)adjustFrameXOffset:(float)horizontal yOffset:(float)vertical hOffset:(float)height wOffset:(float)width;

###UIButton+Helpers

- (void)makeGlossy;
- (void)makeClean;
-(void)setTitle:(NSString*)title;

UIColor

+(UIColor*)colorWithHex:(NSString*)hex;
convenience init(r: Int, g: Int, b: Int, alpha: CGFloat = 1.0)

###Segmented Control

@interface UISegmentedControl (Helpers)
-(BOOL)setSelectedSegmentNamed:(NSString*)name;
-(NSArray*)allTitles;
-(NSString*)selectedSegementTitle;
@end

###Decorate textfields and labels

extension UITextField {

func decorateWithImage(named imageName: String) -> UIImageView

func setBottomBorder(color: UIColor = default) 
}

extension UILabel {
    func addToLeft(image: UIImage?) -> <<error type>>
}

Application View Hierarchy

Find the top most view controller from anywhere. Searches recursively through navigation, Tab bar and modal view controllers in your app window ###UIViewController+Top

+(UIViewController*)topViewController;
@interface UIView (Search)
-(NSArray*)searchForSubviewsOfType:(Class)searchClass;
@end

Backgrounds

BLURRED: For use with a Covers Current Context Modal Transition

@interface UIViewController (Blur)
-(UIVisualEffectView*)blurBackground;
-(UIVisualEffectView*)blurBackgroundOfTableView:(UITableView*)tableView;
-(UIVisualEffectView*)darkBlurBackground;
-(UIVisualEffectView*)darkBlurBackgroundOfTableView:(UITableView*)tableView;
@end

@interface UITableViewController (Blur)
-(UIVisualEffectView*)blurBackground;
-(UIVisualEffectView*)darkBlurBackground;
@end

###To Present and Blur Without a storyboard

@interface UIViewController (Presentation)
+(void)present:(nonnull UIViewController* )newVC on:(nullable UIViewController*)source;
+(void)present:(nonnull UIViewController* )newVC on:(nullable UIViewController*)source withBlur:(float)blurAmount;

###Add Non-Blurred background images

@interface UIViewController (Background)
-(void)setBackgroundImage:(UIImage*)image withAlpha:(float)alpha;
@end


@interface UITableViewController (Background)
-(void)setBackgroundImage:(UIImage*)image withAlpha:(float)alpha;
@end

UITableView Helpers

Reload sections of a tableview

// NOTE This may cause issues :(
-(void)reloadSection:(NSInteger)section;
-(void)reloadSections:(NSInteger)fromSection to:(NSInteger)toSection;
-(void)deselect

Add a header to a tableview

-(void)setupTableHeader:(UIImage*)image;

Navigation Helpers

###Add Tranitions

@interface UINavigationController (Transition)
//add a fade transitions between view controllers for your next push
-(void)addFadeTransition;

//go back, either by popping or dismissing--- but let this figure out which.

UIViewController+Back
-(void)goBackWithAnimation:(BOOL)animates;

Clear Tab bar

uiNavigationBar.makeClear()
uiNavigationBar.unmakeClear()

Keyboard Helpers

UIView
-(void)hideKeyboardOnClick;
-(UIView*)findFirstResponder;
UITextField
-(UIToolbar*)addToolbarWithLeftButton:(NSString*)lTitle withSelector:(SEL)lSelector andRightButton:(NSString*)rTitle withSelector:(SEL)rSelector andTarget:(id)target;

Path Helpers on NSFileManager

+(NSString *)myDocumentsPathForFile:(NSString*)fileName;
+(NSString *)tempPathForFile:(NSString*)fileName;

Gestures

extension UISwipeGestureRecognizer
{
     convenience public init(target: Any?, action: Selector?, direction: Direction) {
}