Software Developer and Coffee Sink.

The university project CUE3 & CueTable created a virtual cooperated media space.

Lighter ViewControllers with Block-based Intentions

Over the past year I have become a fan of creating Lighter View controllers. There a several ways to do this, with Storyboard based Intentions gone to the max. With tricks like User Defined Runtime Attributes you can actually reduce code to a minimum, but I don't like this approach, as you create massive Storyboards to avoid massive ViewControllers.

In the last year I played with several different architectures: target-action and delegation, but I only found blocks useful.

I create lighter ViewControllers with themselves creating the needed intentions with blocks as call-backs. I want to demonstrate it with a ...

Hit Testing Done Right

Hit Testing Done Right

In the past I saw a lot of codes for testing if a UIView was touched by overwriting -hitTest:withEvent: — This is nearly always not what you want, as it is just an pain in the a**.

Instead you should trust UIView's implementation of hitTest:withEvent:, as it will visit all subviews one by one until if finds a hit. 

But how does it know it found a hit? Another method will tell it:  -pointInside:withEvent:

-pointInside:withEvent: is much easier to implement, as it just returns a bool, if it detected a point inside or not. While with ...

An Input Element not only for (possibly big) numbers

An Input Element not only for (possibly big) numbers

I want to show you a bit of code I was working on quite a while ago. I never really finished it and it never was included in any real world app — but I think, it is quite cool, so I want at least make a blog entry of it.

When I was working on a point of sale app for the gastronomy, one of my highest design principal was that it must be useable by one hand only, as the waiter might be using his other hand.

One problem that we identified was the iOS num pad. While it ...

compare NSDates with omitting Minutes, Hours, Day,…

One of the most often asked questions about NSDate on stackoverflow.com for sure is How to compare Dates without time?  and it becomes obvious very soon, that the asker actually does not know anything about the specialties of calendar based calculations

just to name few:

  • Daylight Saving times
  • timezones 
  • Daylight Saving times in different timezones and states
  • leap seconds

If u ever find a code like NSDate *newDate = [ oldDate dateByAddingTimeInterval: 86400]; dont use it. the author isn't aware that the duration of a day in the gregorian calendar can be 82800 to 90000 seconds — and leap seconds will ...

A pattern to switch on an object's value

One control structure of C and many other languages is the switch-statement, that allows to perform different code-blocks depending of a certain variable

switch (n) {
  case 0:
      //execude code for case n == 0
    break;
  
  case 1:
      //execude code for case == 1
   break;

  default:
    printf("whatever");
}

where n needs to be an int or a char (that is actually an int, too) and enums of those types.

But we live in a objectified world today. If it comes to flow-control depending on objects, switch is useless. We need to use if-statement, that can be quite hairy easily.
One could argue, that ...

Variadic Lists and Blocks

Matt Gallagher posted an great article about veridic lists. In his conclusion he writes

In your own code, variadic methods should be used sparingly — passing variables in an NSArray or NSDictionary is safer (if slightly slower and syntactically more verbose) due to the fact that these classes do offer introspection.

And I think he is right.
But now I found a situation, where it makes much more sense to have a veridic list of arguments rather a NSArray or NSDictionary.

I wrote a Category method on NSArray, that allows the user, to filter the array by blocks and create a ...

Beat This, Python!

I love Python. I love Objective-C.

"Huh?!" I hear you thinking, "they are complete different, how can you like both"?

Well, nothing is perfect, even in a lovely relationship.
There are things, that drive me crazy in one — and things that are missing, form my point of view, in the other language

One thing I'd love to see in Python, that Objective-C has, is extending a class — Categories.
Every language should have functional tools like pythons List Comprehensions, but Objective-C hasn't.

But since Apple extended Objective-C by introducing Blocks to the underlaying C, it is now possible to ...