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

Most common functions

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

Perform blocks

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.

performBlockInMainThread {
    // Block executed on background thread.
}

performBlockInBackground({
    // Block executed on background thread.
    }) {
        // completion block on main thread.
}

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

performBlockAfterDelay(0.3) {
    // Block executed after 0.3 seconds.
}

NSDate

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.dateByAddingYearInterval(2)

aDate.dateByAddingDayInterval(5)

NSString

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(fromDate: aDate, style: .ShortStyle)

NSString(fromDate: aDate, format: NSDate.ISO8601StringFormat(), timeZone: NSTimeZone.defaultTimeZone())

UIColor

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

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

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

UIColor(fromHexString: "#FF34DD")

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

UIImageView

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")

UIDevice

Check the current system version:

UIDevice.systemVersionGreaterThan("8.0")

or if it is an iPad:

UIDevice.currentDevice().isIPad

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

UIDevice.currentPlatformName()

UIScreen

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

UIScreen.is4InchScreen()

UIView

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

UIView.loadFromNib("myAwesomeNibFile")

Add rounded corners:

myView.roundCorner(.AllCorners, radius: 10)

Or to quickly access the current width of the view:

myView.frameWidth

Author

kevindelord, delord.kevin@gmail.com

License

DKHelper is available under the MIT license.