by Cesare Rocchi

On Naming Macros in Objective-C

Right after my latest post on naming methods with blocks my friend Murray asked for some feedback on the names for his collection of macros. Without even blinking I suggested ALL_CAPS, having in mind mostly the following macro by Apple UI_USER_INTERFACE_IDIOM() I think it’s pretty ugly to read but I guess it’s meant call out the fact it’s a macro. If you check UIDevice.h though, you’ll find the following: #define UI_USER_INTERFACE_IDIOM() .

Continue reading →

On naming methods with blocks

Recently I have been very busy with the implementation of the BaasBox SDK for iOS and I had to come up with lots of method signatures. It’s 2014 and we all love blocks, so I used them quite extensively. When consolidating the upcoming version I noticed I wasn’t consistent with the naming. Some method was like this: -(void) loadCurrentUserWithCompletion:(BAAObjectResultBlock)completion; and some other was like this: - (void) updateUserWithCompletion:(BAAObjectResultBlock)completionBlock; Notice the different naming for the last part, the name of the parameter.

Continue reading →

Detecting Screen Brightness in iOS

I am a huge fan of small libraries that do just one thing but well. Sure you can detect when screen brightness changes by listening to the UIScreenBrightnessDidChangeNotification, but ASCScreenBrightnessDetector by aschndr is the right sugar on top of that. All you need is to create an instance, set a delegate and implement the - (void)screenBrightnessDidChange:(CGFloat)brightness; method, like this. If you are already using Cocoapods, including it is a breeze.

Continue reading →

Objective-C Categories for Regular Expressions

I am not a heavy user of regular expression but I have tried this new library by John Wright and I find it very handy. It basically allows you to write 75% less code. Here is an example taken from the Readme page While I suggest to know what happens under the hood before using these kind of “shortcut libraries”, I am totally in favor of them when it comes to save yourself some typing.

Continue reading →

Pages(1)