If you are not familiar with this post on why an accomplished Developer does not use Interface Builder, I suggest you read it before reading this post.
I’d like to weigh in on the subject as some of the points shouldn’t – in my view – carry as much weight as maybe he would like them to in that post. It’s not my intention to start a flame war, but I do have a vested interest in there being programmers who use Interface Builder, and ultimately I think that those who are against it just aren’t yet used to it or have understood what a powerful tool it can be.
Choosing Explicit over Implicit
Choosing to be explicit is my number one reason to do things in code instead … they can see right away where everything is and not have to wonder if this file has a NIB.
If you keep your project folders organized such that a folder has a .h/.m/.xib for your object then this is really a non-issue.
I have spent countless hours searching for the source of a bug only to discover it’s some checkbox in one of the half dozen inspectors in Interface Builder. If it was in code, it’s simple to glance at the view code and see the source of the problem much quicker.
If you like writing a lot of boring code to set properties that you can do in a second (and change later just as easily) then do it. This is really a matter of style. Interface Builder is just a part of a toolchain. I also am a very visual person, so I have a better overview of what’s happening with a NIB. Most of the time you are dealing with 2 inspectors. The “I can see it all in code” argument only really applies if you already know what the default properties are supposed to be; so again, you had a learning curve with that.
It is much harder to use Interface Builder for reusable views….
I don’t really understand the meaning of this. I’m starting to suspect that it’s just a matter of experience. Perhaps part of you just doesn’t want to embrace it? As an iOS coder, I ‘grew up’ with it, so can’t understand why people don’t want to use it. (If you want to know how to easily create reusable instances of a UIView from a NIB)
Not to mention, if you use lots of custom views, your NIBs will just be a bunch of invisible boxes. So now you have this tight coupling that is even harder to work with if you were to just lay it out in code.
Did you know about this? There are a lot of runtime attributes for your custom classes you can set up in IB. Also, it’s a tool to build view hierarchies. I don’t know what this argument really is. I really don’t understand how using IB is any tighter coupling than in code, because it’s a code generation tool. In fact, getting your programmers to use it could guarantee that they adhere to a Model-View-Controller pattern precisely because they are prevented from writing too much view code beyond keeping their views vapid and vain; IB helps ensure that.
Have you ever sat staring at some code wondering why it’s not working, only to realize you didn’t connect the outlet or action? I hate that.
I don’t know what to say here. Programmer error? Rookie mistake? I’ve been there too at some point. It’s just a learning curve. Don’t you hate it when an app crashes and you don’t know how to debug it? I hate that too. 😉 It should just work like I imagined it. I will concede that there have been times where I have forgotten to set the delegate, but now I know that this is a source of error once I notice the methods not being called. I guess one can chalk it up to experience.
Working With Others
Have you ever had a merge conflict in a NIB. It’s the worst…. if it gets automatically merged wrong, you might not notice until runtime. With code, you can read the diff and understand what’s happening.
This is where I definitely concede with you, but this is in my experience not a big deal. How many developers does it really take to position objects on a screen? I’ve never been on a project where a developer has said “hey dude, are you done with the NIB file yet?” (Storyboards not included.)
It’s Part of Xcode
Xcode is not the most stable piece of software in the world. The text editing part works pretty well. Every time I get a crash while editing a NIB, I grumble to myself and wish it was code even more. The less I have to use Xcode for more than anything except a text editor with completion and a compiler, the happier I am.
Two things; it sounds like you just don’t WANT to like Interface Builder, and two, you’re not one of those VIM guys, are you? 🙂 Anyway, if you don’t like Xcode, you might try AppCode if you’re not using it already.
Location, Location, Location
Layout code is not hard. Trying to work with auto-layout in Interface Builder is maddening … it’s so simple to just override
layoutSubviews and do your thing.
True, and true. Let’s not forget that time is of the essence, so spending time writing lines of code that can otherwise be set with a mouse-click is a task for people working jobs with big budgets. For the rest of us, anything that will speed up the amount we can get done (well!) is appreciated.
You can simply reuse your code instead of create this tight coupling.
I still don’t understand how you think there’s tight coupling going on. But anyway, with IB I set the rough position and the auto-resize properties, then do the rest in layoutSubviews as well. Screw Autolayout. I don’t know anyone using it, or who has a real use-case for it.
Interface Builder itself is not bad.
It does encourage bad practices…
I completely disagree, and still haven’t found where you’ve made your argument for this, sorry!
…prevents reusability (making working with others more difficult)…
How? I just don’t see your argument here. It gets compiled into code. A chunk of code with an interface (outlets and actions).
…and slows your workflow.
If this were true, why would it exist?
Personally, I avoid using Interface Builder (including storyboards) as much as possible. All of the projects I’ve worked on since 2009 haven’t had NIBs unless it was out of my control.
Storyboards are a slightly different topic that I’ll just leave alone. I don’t use them either because I actually want to write controller code, and I think Storyboards take too much of that away, but feel free someone on the interwebs to dispute that.
I think you should save yourself some time, learn a few things, and start moving to code. We are programmers after all.
We are creative people who solve problems, we programmers. If you were a carpenter, you could saw everything by hand and talk about the purity of your craft, or you could get yourself a fancy woodshop and produce products at a faster speed. So, your job as a programmer is to build something, and build it well in the quickest amount of time possible. If you think this is best accomplished without Interface Builder, then that’s your right. But ultimately all I can say about the “I can’t see what’s happening” and “it slows my workflow” arguments is that you just need to gain some experience with it. I think it’s a fantastic tool that helps one get an overview of what it’s going to look like at runtime, and saves one having to write a lot of boring code. You can even drag elements onto your .h/.m files and it will automatically create the outlets for you. So much LESS typing, allowing you to focus on interesting parts of your application.
If you really are against Interface Builder, then I suggest having a look at DCIntrospect, a very very handy tool that allows you to tweak your view hierarchy (especially frame positioning so you can nudge a view to the left, right, etc until it’s *just right*) at runtime, so at least you don’t have to nudge a frame’s value, compile, run, check, repeat until correct.