I'm working in a company where we have several iOS developers and we use GIT to work in the same projects together. We never use Storyboards or .xib files in our development process as it's nearly impossible to merge them correctly.
With the introduction of the iOS7 I thought about the fundamental differences between Storyboards and coding all the UI "the old way", without the use of Interface Builder.
Is there anyone here who does just that? And most importantly, is there something you CAN do in Storyboards that you can't do in code in XCode 5?
I'm going to split your question into two: NIBs, and storyboards.
As far as NIBs are concerned, source control issues can be painful but manageable, mainly because you've typically got one NIB file per view controller. You could imagine a situation where you have two developers working on two different sections of your NIB powered app without any merging issues. Storyboards are different, since you have one single file that describes most - if not all - of the UI of your application. Clearly there is a far greater potential for conflict issues there.
NIBs can be extremely useful and time saving, if used correctly. Here's an example: the iPhoto App on iPad has a very complex UI. The vast majority of that UI is laid out programatically. However, the app also uses NIBs to load in graphical elements which are then laid out in code. This is how the brush panel works - all the brushes are created in a NIB. This means that Apple don't have to have dozens of identical image/image view alloc/init pieces of code. All the creation can happen in a NIB (this was discussed in some detail in a WWDC 2012 session on the iPhoto UI - it's well worth tracking down).
So NIBs - sometimes good, can save you a lot of time, and whilst there are merge issues they can in many cases be easily managed and handled.
Then we come to storyboards. Storyboards are interesting. On the one hand, they are extremely helpful and useful for straightforward apps and developers new to the platform. I've just converted a UINavigationController based app from NIBs to storyboards and found some significant time savings (particularly around table views, since with storyboards you can take advantage of prototype cells).
However, if you're working on a large scale project with several developers I'm not convinced storyboards are that beneficial. There are, as you say, big issues with merge conflicts, and unlike NIBs it's not easy to resolve them since that single storyboard file controls all of your app UI.
Here's what I'd suggest (and feel free to ignore me!) - if you're currently developing apps and doing your layout/UI entirely in code consider whether NIBs might save you time. They may well not - they're not for everybody - but it's well worth at least considering. You may be surprised at how many large apps actually use NIBs (iPhoto, as I mentioned, but also many built-in apps provided by Apple, as well as many popular third party apps by large teams). I probably wouldn't consider storyboards unless you were a sole developer working on an app with fairly straightforward navigation. That's not to do down storyboards in any way - I love using them - it's just they're not really suitable for collaboration.
Somebody posted this comment in reply to your question - I wanted to discuss it:
There is nothing you can do in storyboard and can't do in code. Objects, gesture recognizers, segues, even constraints - are all available for you to build programmatically
This is technically true, but in reality there are things in storyboards/NIBs that are much easier than code. A good example of this is auto layout. Whilst you can certainly manage your auto layout contraints entirely in code, the harsh reality is that the ASCII auto layout representation is much harder to work with than the visual representation you get in IB. This is especially true on XCode 5, where there are massive improvements to auto layout in IB (I can't detail it too much as it's still under NDA, but Apple publically talk a bit about the changes here).
For me the only big drawback of storyboards is the slow loading time and the usual lag that comes when navigating the storyboard. I'm not talking about 2-5 view controllers apps. I'm talking about 10 and more...
My personal preference is smaller storyboards if I really have to use them(UITableView prototype cells) or just plain xibs.
Doing it in just plain code is just a matter of .... do you have enough time on your hands? :) Usually you wont gain a lot from doing it this way.
You should consider these issues in your dessision:
Development time -
Obviously, working with the xcode UI designer is much more faster and easy to learn when creating new applications from scratch.
In the programmatically way, you will have to define in code each and every element property you'll want to set.
Working with storyboard will make the development process much faster.
Code reuse -
When working with storyboard you will have to bind UI elements to the controller with bullets that adds additional hidden code in the storyboard file. Same stubs are added when creating segues between controller.
This addition hidden code will make make it more difficult to reuse the controllers in other apps that you'll build.
If you are planning to make mass reuse of you controllers code, than creating the UI elements programmatically will be more suitable.
Source code integration -
Conflicts resolving is a common thing when several developers commits changes to the file.
Creating and changing UI elements with storyboard additional changes are added to the storyboard file that sometimes makes the conflicts resolve kind of tricky.
On the other hand, when changing UI elements programmatically only the changes that you'll make will be added the the controller file.
Related
We are a team, creating a very big application for iPad that serves as an eReader for unprivileged children. The app is built halfway and I thought we should take a step backwards and review the whole design of the application. The application we are building should be very, very compliant with the current software development architecture practices for iOS. I have the explanation along with the questions below:
The application right now, has about 50 views (and increasing) and most of the Top-Level views are in the Storyboard (a single storyboard, that is) and the others are in XIBs (for the sub-views, reusable item renderers etc).
Is this approach alright?
Should XIBs be completely omitted for the modern iOS applications?
Should the storyboard be right the way it is or should it be broken down into sub-storyboards? If they should be, how should the exact process of decomposing the storyboard be done? How would the modules be determined?
If you have some tips to manage the application in the right way or some rule of thumbs to assist in a streamlined and modular application, please mention it in your comments.
I'm sorry for the long text up there and I thank you for reading.
This is a bit of a subjective one, but in my opinion it is still valid, and desirable, to use Xibs alongside storyboards. The idea of storyboards is nice, but with the current implementation they are definitely lacking some functionality, the most glaring of which is view reuse. I have worked on a few large projects recently, and storyboards always start out nice, but sooner or later you find yourself copy and pasting table cells, and then controllers, and then you have to change things in multiple places with each update, which is totally unmaintainable. So yes, definitely stick with the Xib files for reusable views.
I am less keen on the idea of multiple storyboards however. While this is easy enough to achieve technically, for me it invalidates the purpose of storyboards entirely. Their only use is as a (relatively) clear overview of the flow of controllers through the application. They add a few small conveniences, but in general I find they often create more code than they save, and create some odd code patterns (eg prepareForSegue:, having to temporarily store ivars when you want to segue to a controller in code that needs properties setting). As you say, how do you split up the storyboards into sub-storyboards? I can only think that whatever partitioning scheme you choose would be somewhat arbitrary, and liable to change at a later date when the app structure changes, which would be no fun at all. Maybe if your application has distinct modes of operation it makes sense to split up the storyboard, but I don't think this would apply to most apps.
So, IMO, single storyboard but use Xibs for reusable views.
I have a question about universal app. My app will not have storyboards or xib file. There is possibility to write universal iPhone/iPad application without it? I found some tutorial how to create universal app with storyboard, but i don't want (i can't) use this feature in my project.
If it is possible What should i do? If i have to made changes only in ViewControllers? I'm start to do this, i'm not changing old project so i can do anythng - what should i learn/what should i remember?
I'm targeting to iOS 5.
EDIT:
I have a screen information in resource file and my rootViewController or any other ViewController will be created in compile time, so i can't have xib file for that, i can't put button on xib with Interface Builder becouse i don't even know how many buttons i will have there. I don't know how many screens i've got till i hit run in my project.
Not only can you write any type of iOS app without Interface Builder, it is actually much more testable and pliable. Some auto layout tricks are difficult (not possible?) in IB style projects, as well.
There is an incredibly impressive library called Masonry that wraps the NSLayoutContraint syntax. This makes it quite pleasurable to subclass views while not having to use ugly VFL or incredibly verbose NSLayoutContraint syntax (not even going to address frame setting...blech!). IB style apps also promote bad software development practices and anti-patterns (just dumping everything in a view controller presentation-wise. No Separation of Concerns!). Also, it is more difficult to work on larger teams (IMHO even small teams) while utilizing Nibs, Xibs, and Storyboards due to merge issues.
On top of all of that, you gain a much deeper understanding of the classes you are working with (UIView, UIResponder, etc.) when writing code in this manner (once again IMHO). There is an interesting article outlining some of these issues in more detail: http://doing-it-wrong.mikeweller.com/2013/06/ios-app-architecture-and-tdd-1.html This is by no means the only article that discusses this problem. Also, this will help for your app delegate: creating a universal window-based iphone app without generated xib file
This is certainly possible, I have only used storyborads once in the many apps I have published. As for not using XIBs, I am not sure why you would want to do that. You can lay out your views at runtime in the init method, but I feel like that is just making things unduly hard on yourself. You can set a XIB up for the iPad and one for the iPhone so you can tailor the UI specifically to each device.
Perhaps if you go into a bit more detail about why you are imposing this requirement on yourself we can discuss if it si worth the effort to go down that road.
Good Luck.
Having used storyboards for a while now I have found them extremely useful however, they do have some limitations or at least unnatural ways of doing things. While it seems like a single storyboard should be used for your app, when you get to even a moderately sized application this presents several problems.
Working within teams is made more difficult as conflicts in Storyboards can be problematic to resolve (any tips with this would also be welcome)
The storyboard itself can become quite cluttered and unmanageable.
So my question is what are the best practices of use?
I have considered using a hybrid approach having logical tasks being split into separate storyboards, however this results in the UX flow being split between the code and the storyboard. To me this feels like the best way to create reusable actions such as login actions etc.
Also should I still consider a place for Xibs? This article has quite a good overview of many of the issues and it proposes that for scenes that only have one screen, xibs should be used in this case. Again this feels unusual to me with Apples support for instantiating unconnected scenes from a storyboard it would suggest that xibs won't have a place in the future but I could be wrong.
You are correct, breaking up the storyboards is the best way to go. Decomposition does more than just make parts of the UI more reusable. It also makes using storyboards in a team more manageable.
Lately, many of my storyboards have contained four or less scenes. It is easy enough for one person to solely build and maintain one or more of such UI modules. This practice reduces or eliminates merge conflicts.
In the case I do need something changed in a storyboard owned by someone else, I ask the owner first if he or she has any local changes. If so, I sometimes have the owner add the changes for me. Decomposition still requires some coordination, but it is substantially less than a full-app storyboard. Ever since I started this practice, I haven't had any merge difficulties.
As for XIBs, I don't think I wrote enough about them in my article. They are still very useful. They can be nice for single view controllers. However, this is not where they truly shine. XIBs have one advantage that storyboards may never have. The most basic unit of a XIB is a UIView, whereas the basic unit of a storyboard is a UIViewController. Since XIBs can hold collections of UIViews, they are great for visually creating custom controls. In a XIB, I can visually build a rotary dial or a GPS widget. Then I can drop these controls and widgets into storyboards or other XIBs. Such XIBs are seen more often in iPad apps since they have larger screens capable of holding many controls and widgets. It would be unnatural to build a UISwitch within in a UIViewController in a storyboard.
Now for the best news. It is possible to connect storyboards within Interface Builder and without writing any code. I was planning on releasing this technique after WWDC, since Apple may release similar functionality in iOS 6. However, since you asked, I decided to release it now. Rather than duplicate my explanations on how RBStoryboardLink works, you can find more details on my blog and on GitHub. This will make your UIStoryboard experiences much more enjoyable.
I found this article mentioned a lot of issues when using StoryBoard, one thing the author raised is using a huge of nib files in one StoryBoard, which I agreed he shouldn't do that, but there was other issues such as:
My root view controller has become a source view controller for lot of
segues and therefore its prepareForSegue: has become a stupidly large
method filled with a lot of “if (segue.identifier
isEqualToString:#”…”)” statements in a row
and
It is possible to assign view controllers in a storyboard an
identifier. Unfortunately this identifier property is not exposed in
the UIViewController class. This makes it very hard to perform safe
introspection of the view controller hierarchy at runtime. It would be
really nice if identifier was exposed for view controllers as well as
for segues.
and ...more other issues, I thought it does make sense, and I'm worry whether should or shouldn't use StoryBoard for now ??
I recently worked in a ipad project. I find no nib files in the entire project. Is there a specific reason for such standards? I find it really difficult to follow that kind of project.
I'm not sure I would consider this a "standard". Some devs just prefer to code all their views as opposed to using Interface Builder. The initial releases of IB were a bit flaky and people avoided it due to this. I don't really see any reason to avoid using IB nowadays unless you are doing a completely custom user interface or a game. In the case of a custom UI, it might be easier to build it up in code compared to trying to bend the IB elements to your will.
a nib, particularly if localized, breaks DRY.
initialization is beyond your control when using a nib.
code and program reuse is more difficult. consider libraries and multiple apps.
it's easier to manage/update an implementation from fewer locations/files/resources. let's say you want to change the app's color theme... very painful if you have to modify all the app's nibs, as opposed to changing the definition of a function. also pretty close to useless if you layout the groundwork at the source level for color themes in addition to using nibs -- at that point, you're already setting up your views programmatically.
improved performance (where that's important).
program security. IB used to support plugins/addons in osx... those were just removed.
frameworks are not an option in iOS. nibs can't be shared via libraries as easily as compiled programs.
for long term and large scale development, it makes a lot of sense to write it programmatically, whereas IB's really handy for prototyping.
Agreed, IB is pretty stable and a lot more featured that it used to be. Although iirc using IB does add more weight to the project than if it was all done via code.
I have been programming with the iPhone SDK for some time now.
I have not been using Interface Builder. This scares me a little. I know that in effect I may be 'fighting the framework' but I do not see it that way.
I find it very easy to just instantiate my UITabBarController in my app delegate, instantiate a UINavigationController, then push and pop view controllers as I go.
Naturally I do not have an extensive knowledge of how to architect an app with XIB files because I have never done so, however I do know the general gist of it, having built some Mac apps in Cocoa using NIBs. So I am not completely ignorant.
My question is whether there is an increase in development time when choosing to lay out UITableViewControllers and UIViewControllers using XIBs rather than programmatically instantiating them and then setting up the ivars.
As I see it, both methods still require you to subclass the view controller for customization which will probably occur for the majority of your views. As well, there are still manual classes required for delegates, and the process of connecting outlets from within the XIB seems comparable to me from setting an ivar.
Or am I missing some other major point?
Thanks!
Code takes much longer to write to configure UIs than IB does.
Plus, you can hand off design to designers and let them tweak the UI.
In the end they both accomplish the same thing. You should use either one depending on the circumstances. Most of the time writing the code to create and position views, and especially maintaining it down the road, will take much longer than using IB. In a simple app for the iPhone though, this might not be true and you'd be just as well off creating everything in code. Basically, you should know how to do both, and pick the path that involves the clearest code and quickest development.
IB shines when you're using it to actually lay out views; even two or three views can be a real hassle to lay out and configure in code. I do tend to use it for tab bar and navigation controllers, and sometimes for subcontrollers (usually only if I think the user is very likely to use it), but that's more just because I'm already there so I find it convenient.
With this new version 3 OS they're announcing next week, I'm hoping Interface Builder gains some of the flexibility it has in Cocoa, where you can add palettes for your own classes and even build up complex non-view data structures (by using custom palettes). We'll have to see, though.
Don't worry too much, IMO Interface Builder is a little over-rated too.
It's definitely useful for getting things up and running quickly, or if you have an app with a lot of screens that are tedious to setup, but you're not missing much.
For the uses you outline just doing things in code is fine, and possibly even a little easier to understand.
Laying out views, or custom cells though... then you get into a ton of font/color/position setting that quickly explodes into a lot of code, hard to maintain and tweak. Much easier to adjust what you want in IB in those cases.