If you have code (objective-c) within a method that you would like to condense to a single call (for brevity or readability) what is the preferred practice.
- don't do it, keep all related code in the method.
- Add a new method to the object in question i.e. - (NSString *)formatedTime;
- C-Style functions, defined outside the object in question.
- Other i.e. something I missed.
The other thing that I'd say is that if you break out code into additional helper methods you should declare those methods in a class extension, rather than the main header for the class. Here's an example .m file:
This is similar to johnw188 hint, but goes a little bit further:
In a class extension you cannot only have private methods but private properties too.
The benefit is quite clear: You get the @property/@synthesize power, but only access it from with-in the class object. private properties are only accessible on
self
.My primary rule when rewriting code is always to ensure whatever I write is as readable as possible. With that in mind, then, I usually: