I usually return nil when there's no data to return. e.g.
- (MyObject *)myMethod:(MyParam *)param {
MyObject *object = nil
if (param ok and there is enough data to calculate on) {
object = results of some calculations
}
return object;
}
But I got into a discussion with a colleague (a Java programmer and Object Orientation purist) who thinks this habit is error prone or at least yields a lot of conditional statements where one has to verify that returned data isn't nil. Where appropriate I also pass an NSError parameter along with param.
What's your take on this, is there a better cleaner way?