Helpful Swift extensions

swift-extensions

Well, I’ve been dipping my toes in Swift for the past couple of months and I have grown a few extensions that I would like to share: an extension for String class and UIColor class…

Wouldn’t be nice to be able to access String instances and get sections of it (substring) as a new String but with a simple syntax?

Wouldn’t defining UIColor instances with a String make life easier for developers when working with graphical designers?

Continue reading

issues with Google Analytics and iOS 7 background fetch

preview_image-2

Since the introduction of iOS 7, there’s an abundance of articles that explain how to use iOS 7′s background fetch to download data for your apps while the phone is in it’s downtime.

Background fetch can be used to update weather information, traffic report status, load new articles, etc. It’s a way for your app to reach your server and update the user’s screen during downtimes (phone not being used, phone is sleeping and being charged).

iOS uses a bunch of factors before giving your app the precious time-slice (around 30sec max) in order for your app to do its business. The faster you execute the process, the more chances the OS will give you future time-slices. The more processor intensive you are, the less likely for the OS to give you time in the future.

This is all well and good, and I have recently launched an app update that uses this feature to the App Store.

What came next was perplexing…

Continue reading

Cool UIColor category

When working with graphic designers for interface design you get a lot of color codes like #17d3ff and #555 (basically HTML color codes) and using UIColor main methods could be a pain.

To set color #17d3ff using Obj-c

UIColor* color = [UIColor colorWithRed:0x17/255.0f 
                          green:0xd3/255.0f 
                          blue:0xff/255.0f 
                          alpha:1.0f];

It’s a mouthful.

Luckily nicklockwood has created an great Obj-c category for these specific needs. It has a lot of utility methods added like colorWithString which takes an HTML color codes directly

        UIColor* color = [UIColor colorWithString:@"#17d3ff"];

Much much better, and it also keeps the readability of your design code much easier to follow.

Try it here.

I have also made a fork that includes some more utility functions like “darker/lighter” shorthands.

Try the fork here