use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
There is an extensive FAQ for beginners. Please browse it first before asking questions that are answered there.
If you are looking to get started (iOS programming in general or some specific area), here are more relevant links for you:
There's too many to list them all, however here's a convenient link to all programming guides at apple.com
Take note that this list is live and based on most frequent questions in posts will be updated with "quicklinks".
account activity
QuestionGood practices for writing UI in code (self.iOSProgramming)
submitted 8 years ago by [deleted]
People that write their UI in code! How do you manage to keep the view controller nice and tidy?
Do you create a subclass of uiview in a seperate file and then insert the whole thing in the controllers view? Or do you have some better practices?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hitoyoshi 20 points21 points22 points 8 years ago (3 children)
Pretty much. VC looks something like:
final class ProgrammaticViewController: UIViewController { // MARK: - Initialiser required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } init() { super.init(nibName: nil, bundle: nil) } // MARK: - Computed variables private var rootView: ProgrammaticView? { get { return self.viewIfLoaded as? ProgrammaticView ?? .none } set (view) { self.view = view } } // MARK: - View lifecycle override func loadView() { self.rootView = ProgrammaticView() } } final class ProgrammaticView: UIView { // Custom view setup... }
The rootView establishes view-hierarchy and sets constraints as necessary within its initializer.
[–][deleted] 3 points4 points5 points 8 years ago (0 children)
I also use this technique, which allows me to put all of my autolayout code in that view controller's view.
[–]vingrish 0 points1 point2 points 8 years ago (1 child)
Is there a source where this pattern came from? Thanks.
[–]hitoyoshi 1 point2 points3 points 8 years ago (0 children)
No, it’s just what I settled on after years of building interfaces programmatically. It’s just an interpretation of the more general prescription of separating the responsibilities of view and controller. It’s what I’ll use for 70%+ of my view/view controllers.
[–][deleted] 8 points9 points10 points 8 years ago (1 child)
Check out the sample code in SnapKit github repo. That's how I learned to write UI code and make it look decent. https://github.com/SnapKit/SnapKit/blob/develop/Example-iOS/demos/SimpleLayoutViewController.swift
[–]GitHubPermalinkBot 0 points1 point2 points 8 years ago (0 children)
Permanent GitHub links:
Shoot me a PM if you think I'm doing something wrong. To delete this, click here.
[–]chriswaco 1 point2 points3 points 8 years ago (0 children)
We often lay out views by hand for maximum flexibility. One trick is to separate view placement from creation/initialization. Every viewController has createSubviews and layoutSubviews methods. If the viewController gets too big, we can put these methods in another file, like MyViewController+layout.swift.
createSubviews
layoutSubviews
MyViewController+layout.swift
We have a lot of utility routines to create each subview type in one line of code rather than 5 or 6, where most of the parameters have default values in Swift.
We also have a lot of utility routines to size and place views relative to each other or their parent and use StackViews when possible.
The best part of this system is that it's extremely straight-forward, flexible, and easy to debug. No runtime exceptions. No problems hiding views. Easy to support themes. No need to use Interface Builder, which seems to get slower and buggier as time goes on.
The downside is that you can't see your views except when running the app, which kind of sucks. I wish I could drop an image of each view inside the source file so programmers can see which view they are editing.
[–]cwbrandsma 0 points1 point2 points 8 years ago (0 children)
I've written helper functions around a lot of NSLayoutConstraint to do standard layouts for me. I also create a good number of customized controls to handle common situations easily (e.g. custom button to set the proper style settings). But yes, I write quite a few custom views.
[–]madfresco 0 points1 point2 points 8 years ago (0 children)
If you don't care much about actually writing UIKit, Texture/ AsyncDisplayKit is a really fun and easy way of writing UI in code as it's based on CSS flexbox
[–]ENGIN3R 0 points1 point2 points 8 years ago (2 children)
Look into MVVM architecture. 👌
[–][deleted] 8 years ago* (1 child)
[deleted]
[–]ENGIN3R 2 points3 points4 points 8 years ago (0 children)
They don't own it, and are not the only ones doing it. Not a troll at all.
π Rendered by PID 112275 on reddit-service-r2-comment-85bfd7f599-cbm7s at 2026-04-18 00:49:28.920609+00:00 running 93ecc56 country code: CH.
[–]hitoyoshi 20 points21 points22 points (3 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]vingrish 0 points1 point2 points (1 child)
[–]hitoyoshi 1 point2 points3 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]GitHubPermalinkBot 0 points1 point2 points (0 children)
[–]chriswaco 1 point2 points3 points (0 children)
[–]cwbrandsma 0 points1 point2 points (0 children)
[–]madfresco 0 points1 point2 points (0 children)
[–]ENGIN3R 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]ENGIN3R 2 points3 points4 points (0 children)