Live data from Hacker News

Your First iOS App – 100% Programmatically

blog.austinlouden.com

21–30 of 111 posts

Re: Your First iOS App – 100% Programmatically

#21
I've finally arrived at the fascination with learning something by just starting with nothing and building onto it one step at a time.

My first two to three years of programming were spent jumping into random tech (like Rails, SQL, jQuery) and faking it til I made it (although we all still fake it with jQuery). I didn't necessarily understand my tools but it let me rapidly gain a feeling for how tools come together.

But now that I have a fledgling intuition and opinion on how software can be put together, I've gone off the deep end this year and have been learning from the other end of the spectrum: By starting with a blank canvas and using no other reference than API docs and maybe some Getting Started blog posts if I get stuck.

Some examples:

* Learning Emacs starting with nothing but `C-h` and Open File (`C-x f`). Don't install a plugin until you've toiled with the vanilla way for a while.

* Building familiarity with Linux by installing Ubuntu on a VPS/VM/partition and slowly creating your own bash aliases for commands. Like `untar` instead of `tar -xzvf` or `ag-install`, `ag-upgrade`, `ag-depends` for the various apt-get commands. Read the man pages and see if you can improve your abstractions (aliases) with options you didn't know about. I don't remember the iptables file location. I just type `edit-iptables`.

* Learning iOS dev via RubyMotion which has a really nice cli workflow.

* Learning Clojure's Ring, Ruby's Rack, Python's WSGI, etc. by making a Hello World app and gradually expanding it piece by piece. Add session support. Params support. Create your own middleware. Then start looking at community middleware.

So that's why I like these kinds of blog posts.

Re: Your First iOS App – 100% Programmatically

#22
I have to say I agree totally the philosophy of this article. I tried interface builder when I first got started on iOS development, but I just found it far too restrictive in terms of creating the sorts of interfaces I needed.

I can see it's uses for simple apps, but when you've got something complicated where there's lots of non-trivial interactions between the different elements and you often want to change certain parts of the interface (like adjusting the set of buttons visible on the toolbar depending on the mode you're working with), interface builder doesn't really cut it.

Perhaps this is just my nature - I prefer expressing things programatically and having everything defined in code (or in a suitable declarative language). It gives me a lot more control over how changes in the UI happen. But it depends very much on your background and the type of app you're developing and I can understand its appeal for some developers.

As always, you should choose the right tool for the job.

Re: Your First iOS App – 100% Programmatically

#23
post #3

So, a word of advice to new folks trying out iOS land: Interface Builder is most emphatically your friend. The compile/debug cycle in iOS is sufficiently lengthy that laying out views programmatically gets very tedious very fast. Besides realtime previewing of exactly how your view is going to look , IB also helps you understand how your layout is affected by rotations to landscape and differences in view height betw…

I agree with pretty much everything you say (especially now Apple will be pushing auto-layout for newcomers to the platform), but the one thing that's really bothered me with the "Your First iOS App" tutorial is that as some point it switched from NIBs over to a full Storyboard. And Storyboards are certainly in principle a cool idea, but I've never seen a production app that has actually used them (please do correct…

I'm writing a fairly complex iOS app, and I opted in for storyboards in it. It doesn't handle 100% of navigation, because I only was invited to work on the app at some point and I didn't feel to rewrite the whole thing, but I use it for a substantial part of UI. It gets a while to get used to, but then you have this very cool overview of this whole part of the app. Some static parts are done 100% in IB (like a menu with grouped-style UITableView, utilizing static cells), others only use placeholders which are filled in code. But it works, and it works pretty well.

Re: Your First iOS App – 100% Programmatically

#24
post #3

So, a word of advice to new folks trying out iOS land: Interface Builder is most emphatically your friend. The compile/debug cycle in iOS is sufficiently lengthy that laying out views programmatically gets very tedious very fast. Besides realtime previewing of exactly how your view is going to look , IB also helps you understand how your layout is affected by rotations to landscape and differences in view height betw…

I agree with pretty much everything you say (especially now Apple will be pushing auto-layout for newcomers to the platform), but the one thing that's really bothered me with the "Your First iOS App" tutorial is that as some point it switched from NIBs over to a full Storyboard. And Storyboards are certainly in principle a cool idea, but I've never seen a production app that has actually used them (please do correct…

How would you know if a production app was using Storyboards? I just submitted my first "Storyboard App" . It was a little uncomfortable for me seeing as I have gotten used to using NIBs, but I did it because I assumed Apple was moving away from NIBs.. I wonder how other people who use Storyboards do it..I pretty much had to sit at a desk with my MBP connected to external monitors anytime I wanted to do any work, just because the Storyboard required a lot of screen space.

Re: Your First iOS App – 100% Programmatically

#25

So, a word of advice to new folks trying out iOS land: Interface Builder is most emphatically your friend. The compile/debug cycle in iOS is sufficiently lengthy that laying out views programmatically gets very tedious very fast. Besides realtime previewing of exactly how your view is going to look , IB also helps you understand how your layout is affected by rotations to landscape and differences in view height betw…

Writing code in iOS is tedious, but IB is also dog slow and XCode becomes pretty unresponsive every time I switch to/from it. Not to mention the mess xibs make in source control. There is no reason for xibs to be human readable -- a binary format would limit diff hemorrhaging, and performance would certainly be helped by not having to process unholy amounts of XML. Either way, good luck merging xibs with multiple collaborators.

Re: Your First iOS App – 100% Programmatically

#26

So, a word of advice to new folks trying out iOS land: Interface Builder is most emphatically your friend. The compile/debug cycle in iOS is sufficiently lengthy that laying out views programmatically gets very tedious very fast. Besides realtime previewing of exactly how your view is going to look , IB also helps you understand how your layout is affected by rotations to landscape and differences in view height betw…

I jumped into iOS dev after storyboards so, I fear nibs... I've never used one. If I started with a storyboard, should I throw in nibs every now and then for certain tasks??

Here's the haphazard way I'm using this stuff these days:

1. Non-view controller views. These typically go in nibs. Custom tableview cells, tableview headers used across multiple views, custom buttons, nibs are all fine for this. (And the UITableView API accepts nibs for setting up reusable cells.)

You can certainly do custom tableview cells in Storyboards, but it's weird because I don't know how you can re-use those cells across multiple tableviews.

2. View Controllers. These I'm often using Storyboards to build. Since they're great for static tableviews, Storyboards end up having a decent chunk of stuff built in them lately. It can be nice to look at two views side by side. I seem to be grouping related view controllers together in single storyboards.

Nibs have performance penalties if they're packed down with too many objects, as every single one has to be loaded into memory. My understanding with Storyboards is that they don't have this drawback, so that's helpful.

Re: Your First iOS App – 100% Programmatically

#27

So, a word of advice to new folks trying out iOS land: Interface Builder is most emphatically your friend. The compile/debug cycle in iOS is sufficiently lengthy that laying out views programmatically gets very tedious very fast. Besides realtime previewing of exactly how your view is going to look , IB also helps you understand how your layout is affected by rotations to landscape and differences in view height betw…

I've been a Cocoa developer for close to a decade now, and I've gone back and forth on this many times, but by now I've settled 100% in the nibs-are-evil camps. There are several reasons for that:

- Nibs are a nightmare when working with version control and merge tools. Now, at least, they are XML instead of a proprietary binary format, but it's still a joke…

- Auto-layout in IB is provably the worst GUI I have ever used. It's completely impossible to make it do what you actually indent. I was one of the guys cheering and wooing in the audience when it was announced at WWDC 2011, but it's proven to be a huge flop.

- I have a similar experience with storyboards.

- Having classes that may be instantiated both from code or from NIB deserialization adds a layer of complexity and messiness to your app.

- Ultimately laying out your views in code doing some simple arithmetic is easier to reason about and more likely to do what you expect. (People have no problem doing it to lay out websites with CSS–it's not that complicated.)

At the end of the day, nibs make it a little easier to get started (like using Ruby on Rails, and the Active* set of libraries), but it does not belong in a serious project, as it would add a prohibitive amount of technical debt.

Re: Your First iOS App – 100% Programmatically

#28
post #4

I made a fake account to ask this question b/c I'm too ashamed not to know this: Is there an equivalent Visual Basic-style editor for making iOS apps? You just place the button, double click on it, add functionality, drop in elements and you're off the races? Just looking at this tutorial, it is astonishing how much knowledge you need to have to get up & running and create something so simple like a HelloWorld exampl…

While learning how to do this stuff in code is a good exercise, it's much better to do these things in IB when possible. Here's the same app done in IB:

http://dl.dropbox.com/u/1127246/Screenshots/op4t.png

This is it, that's the whole app (there is also an AppDelegate which I didn't even open and contains virtually no code). There are literally 3 lines of code written by me here (compared by 40-50 lines in the article). Everything else is generated/hooked up in the NIB by Interface Builder. This was done in about 2-3 minutes.

In fact, this code performs better than the one from the article, because it uses Auto Layout. So when you rotate the device, you get a desired outcome:

http://dl.dropbox.com/u/1127246/Screenshots/rulo.png

If you do the same with the app from the article, you'll see this:

http://dl.dropbox.com/u/1127246/Screenshots/sncv.png

And then you'll have to write another bunch of code in layoutSubviews method, or manually create struts and strings or constraints.

Re: Your First iOS App – 100% Programmatically

#29
post #24
post #3

Earlier quoted context omitted.

I agree with pretty much everything you say (especially now Apple will be pushing auto-layout for newcomers to the platform), but the one thing that's really bothered me with the "Your First iOS App" tutorial is that as some point it switched from NIBs over to a full Storyboard. And Storyboards are certainly in principle a cool idea, but I've never seen a production app that has actually used them (please do correct…

How would you know if a production app was using Storyboards? I just submitted my first "Storyboard App" . It was a little uncomfortable for me seeing as I have gotten used to using NIBs, but I did it because I assumed Apple was moving away from NIBs.. I wonder how other people who use Storyboards do it..I pretty much had to sit at a desk with my MBP connected to external monitors anytime I wanted to do any work, jus…

> How would you know if a production app was using Storyboards?

Because just like NIBs, Storyboards exist as part of an app's resource bundle, which is easily viewable. It is usually fairly straightforward to examine an IPA from the store and determine whether it's using NIBs and the like.

Re: Your First iOS App – 100% Programmatically

#30
This article, although still great for beginners to get started, is using dated techniques that should be avoided.

In the past, developers would have resorted to starting with interface builder to do their designs. As they continued the development process, theyd notice that more and more of their views had to be done in code because Interface Builder wasn't powerful enough to do what they wanted. It could then be understandable why for newer projects, someone would skip Interface Builder altogether and go for code-only from the start.

Things have changed now though. Auto-Layout is extremely powerful in both Interface Builder and through code. Out of the box your visually designed interfaces now support powerful alignment and resizing irregardless of screen size. This is a big deal because there are a lot of screen sizes in iOS these days (iphone4, iphone5, ipad, all of these in landscape and portrait and yet again all these permutations with and without the keyboard open). auto-layout makes internationalization super easy too as all objects on your interface are designed to get bigger as words get longer (such as in German), yet have all associated objects around them still be perfectly aligned. Even right-to-left languages (and interface re-ordering) is supported without any additional code.

Looking at the code in the article, none of these are supported. If you even turn your iphone landscape the ui will be cut off. Let alone supporting ipad, keyboard open, longer words in the buttons/labels, etc.

I highly recommend new iOS developers to start with Auto-Layout from the getgo: https://developer.apple.com/library/mac/#documentation/UserE...

It's like tables vs css. Use CSS, it's much more portable.

Post reply on HN