Skip to content

kevindelord/DKHelper

Repository files navigation

DKHelper

Build Status codecov.io CocoaPods Carthage compatible License Platform

The DKHelper library is a group of categorized classes containing functions meant to help any developer on his every day work.

Those functions were coded and used for many different projects. Instead of copying them every few days, a library has been made to simplify the this task.

Integration

Add the following to your Podfile:

pod "DKHelper"

And import the header file:

#import "DKHelper.h"

Add the following to your Cartfile:

github "kevindelord/DKHelper"

And import the framework:

// Swift
import DKHelper
// Obj-C
#import <DKHelper/DKHelper.h>

Most common functions

Here is a small list of available functions. Many more are available, please check the full documentation on CocoaDocs.

The DKHelper makes it easier to deal with blocks in brackground or in the main thread. You do not need to remember the GCD syntax or anything.

performBlock(inMainThread: {
	// Block executed on background thread.
})

performBlock(inBackground: {
	// Block executed on background thread.
}) {
	// Completion block executed on main thread.
}

Some functions also exist giving the possibility to execute a block after a certain delay:

performBlock(afterDelay: 0.3) {
	// Block executed after 0.3 seconds.
}

Many functions and properties have been created for the NSDate class.

There are functions to check how old is a date, more than a day or a year?

aDate.isOlderOrEqualThanDayInterval(3)

aDate.isOlderOrEqualThanYearInterval(1)

There are also function to directly get the day, hours, minutes, etc. values.

aDate.day()

aDate.hour()

aDate.minute()

It is also possible to add some time interval to a date. For example add 2 years or 5 days:

aDate.addingYearInterval(2)

aDate.addingDayInterval(5)

There are properties to check whether a string is

an email:

myString.isEmail

a numeric string:

myString.isNumeric

an alphanumeric string:

myString.isAlphaNumeric

But also functions to generate a string object from a date with style or with format:

NSString(from: aDate, style: .ShortStyle)

NSString(from: aDate, format: NSDate.ISO8601StringFormat(), timeZone: TimeZone.current)

There is function to generate a color from RGB, RGBA, and Hexa strings:

UIColor.r(123, g: 46, b: 14)

UIColor.r(123, g: 46, b: 14, a: 0.7)

UIColor(fromHexString: "#FF34DD")

UIColor(fromHexString: "#FF34DD", alpha: 0.6)

It is possible to initialize an image view with a frame and a picture:

UIImageView(frame: aFrame, image: anImage)

Or just with an image name:

UIImageView(imageNamed: "aPicture.png")

Check the current system version:

UIDevice.systemVersionGreaterThan("8.0")

or if it is an iPad:

UIDevice.current.isIPad

or even the current platform name, for example "iPhone 5C (GSM)"

UIDevice.currentPlatformName()

Functions to get to know the size in inches of the current screen.

UIScreen.is4InchScreen()

Loads a view from a nib file within the main bundle.

UIView.load(fromNib: "myAwesomeNibFile")

Add rounded corners:

myView.roundCorner(.allCorners, radius: 10)

Or to quickly access the current width of the view:

myView.frameWidth

Author

kevindelord, [email protected]

License

DKHelper is available under the MIT license.