2

The question is about structuring in iOS

So I receive a message from a company where I passed a test and they say:

"First of all I want to highlight that they said (developers who took my test) that they really liked how clean your code was. One thing where you could improve is the structuring of classes which wasn't ideal."

I asked about what actually I did wrong or what should I improve. I am not sure that this is the stack question, but maybe some one can point me or suggest some thing how for example you structure you code.

I am asking because clean and structure and what about I care every time, but right now I hear that is not ideal.

So usually I write code with the count of lines no more then 250 - 300. I care about pragma marks that separate code into lifecycle blocks, i care about spaces and etc.

So my code is separated also into "folders" where I store appropriate logic elements like:

  • View Controllers
  • Views
  • Constants
  • Models
  • Helpers
  • XIBs (if any)
  • Storyboards (if any)

Each of these folders have subfolders that is not a group as well but real folder on hard drive and each folder contain some classes which named with appropriate name the class does.

I understand there are no rights or examples how to structures project, because it depend on the tasks and developers or company style. But if I receive some message like above, so then maybe can someone suggest something where I can read about or what I miss maybe.

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • Just wondering, "count of lines no more then 250 - 300" per method, class, file? – zaph Oct 27 '14 at 18:06
  • @Zaph, I meant I usually write code for each class with lines no more the 300. Because I separate many component. It is every time mare if you need to support for example view controller with lines about 1000. So it is really hard to manage it. Especially when view controller does all work for you like - download data and etc, it is ugly really. I don't like it and that's why my classes usually have no more the 300 lines and with pragma mark on each points that I won't to mark for another developers. – Matrosov Oleksandr Oct 27 '14 at 19:15
  • That sounds great to me. Last year we caught a developer with one method with over 5000 lines and he defended that. WOW! At a conference I brought this up at a lunch table, one developer thought that was ridiculous, three felt it was OK and one said that breaking it up into many smaller files would be worse. – zaph Oct 27 '14 at 20:10
  • @Zaph 5000 lines??? really? amazing, but it is not a comfortable. I think then you need to scroll instead of develop the same code ) – Matrosov Oleksandr Oct 27 '14 at 22:37
  • 5
    @Paulw11: This is not at all a Code Review question, especially because there is no code to review. It looks more like a general question. Please read our [Help Center](http://codereview.stackexchange.com/help/on-topic). – Jamal Oct 27 '14 at 22:38
  • I suspect their issue was with the structure of the object model they came up with -possibly related to the limit of 300 lines per class - which is why I suggested code review – Paulw11 Oct 27 '14 at 22:40
  • @MatrosovAlexander i think what they mean by structure is not about folders etc but to do with the way to organise and separate your models, views and controllers such that your it follows a design pattern.. see [Wiki](http://en.wikipedia.org/wiki/Category:Programming_principles) for some examples – Shams Ahmed Oct 28 '14 at 00:04
  • @ShamsAhmed, yep I also don't say just about folders. Folders just represent structure of models, view and controllers as you said and contain this elements. So you can trust me I know what is the difference between UIView subclasses and UIViewController subclasses, so I know how to separate them to put to appropriate folder etc. Of course folders are just the folders, but I mean about representation of structure and what each folder stores inside. – Matrosov Oleksandr Oct 28 '14 at 15:46
  • 1
    @MatrosovAlexander in that case see [this blog](http://www.sebastianrehnby.com/blog/2013/01/15/structuring-an-ios-project/) post about Xcode structures. I've now use it for all projects i work with... – Shams Ahmed Oct 28 '14 at 17:02
  • @ShamsAhmed, this really good suggestion with a little difference using universal project. In any case suggestion about subclassing for different devices. – Matrosov Oleksandr Oct 30 '14 at 17:20

0 Answers0