View code organization

Hello

So after building a few iOS apps, I still am having issues figuring out code organization. More specifically, were to put view code. So many tutorials online show View Controller code that tweaks a view’s properties (such as corner radius) or laying out subviews within another view.

I feel that there is a better way. Not sure if subclassing a UIView is a good idea or passing a view controller’s view to a “composer” object (some object that composes the view’s subviews). What I would love to have is some type of markup language such as html or xml (in the same vain as android). While the storyboard/xibs kinda give me a place to specify view styling and layout, it is limited and some things only can be done in code.

If there are any books, blog posts, thoughts, or ideas on this subject I would be very

Thanks
Mike

1 Like

Hello!

Code organization is something we all struggle with. The way UIViewControllers work it can be hard to abstract the view code from the logic. The storyboards can hold onto most things but you will have to drop into code once your view styling becomes somewhat complicated.

Subclassing UIView to create reusable views or cells is usually helpful, although I probably wouldn’t subclass a view if it weren’t going to be reused. I’ve also seen some people use the Presenter pattern and have specific classes used to style and or populate their views with data. We have also been using an MVVM pattern internally to separate the controller and view logic/styling.

The Storyboards themselves are a markup language. If you look at their code, it’s XML similar to Android. The Interface Builder just makes it easier to deal with so you don’t have to know the XML syntax. Android is similar in that it also uses XML for it’s views and has a UI builder to make working with it easier.

Anyways hope this helps.
Tony

2 Likes

Thanks
Glad to hear I’m not the only one. :smile: It drives me crazy. I miss the days of having all my view logic in one area and everything else in another. I end up with half of my view stuff in my code and half of it in storyboards. It’s really harshing my mellow.

I will have to look into using MVVM or the presenter pattern.

Thanks again.
Timko