ios 5 - Code to Reflect on Storyboard - ios

When you create an interface with Storyboard (OR normal IB) the code is generated at compile time for the app. In other words, it does not update the file of the ViewController it is linked to.
Is there a setting that allows for this?
For me I would see that as a great learning tool.
Like if I put a button on a certain place in a UIView, what would that look like in code?
Cheers Jeff

Unfortunately there is no such setting. XIB's and Storyboards are stored as XML files, and rendered into UI at runtime. On the other hand, when you create UI programmatically you write your code in Objective C using Cocoa Touch classes. There is no direct way to convert the XML into Objective C during development.

Related

How to Change the Default ViewController Class Declaration in Xcode

As i've grown as a developer, I've developed my own way of styling and managing my ViewControllers and I was hoping there was a way to change the default ViewController. Being able to customize the default ViewController syntax would save me a considerable amount of time down the road.
Creating a new ViewController:
What i get:
What i want:
As I know you need to create a custom Xcode project template. And your customized ViewController file needs to use this custom Xcode project. It is used for some design patterns sample.
In my opinion if you really use this template again and again worth it creating one otherwise it could be little painful
After some investigation and with the help of this post, it appears there's two viable options - coordinator patterns & code snippets
Coordinate Patterns
Tutorial: Custom Xcode Template
Although the coordinator pattern is doing exactly what is being asked, it appears to be a fairly lengthy and complicated process when compared to code snippets
Code Snippet
Awesome Reference: Xcode Snippets
By highlighting all of the code that is defined in my default ViewController, right-clicking, and selecting "Create Code Snippet", I was able to define a new snippet which can be accessed by clicking the "+" on the top right corner of Xcode (with focus being on a swift file and not a storyboard file) You can even define Keywords for the autocompletion to work off of.

Can Xcode Add Items To A Storyboard, In Editor, Through Code? [duplicate]

So far I have seen documentation of how to write a storyboard with Interface Builder. I prefer writing the code manually though. Can a storyboard be developed manually without interface builder in xcode?
I would not recommend this, however, if you right click on your storyboard file in the Project Navigator choose the option Open As > Source Code you can hack away to your heart's delight.
I would imagine you'd prefer editing a Storyboard using IB as you'll just be creating more work for yourself debugging various syntax issues that the editor would have abstracted away for you. Note, that the XML is compiled at build-time into the binary files called nibs, then loaded and instantiated at run-time to create the views. Getting your hands dirty with that will slow you down.
https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/Edit_User_Interfaces/edit_user_interface.html#//apple_ref/doc/uid/TP40010215-CH6-SW1
BTW #Kenny's suggestion to write your views in code is a good one if you really don't want to use XIBs or Storyboards
If you prefer writing code, I would suggest doing everything programmatically and not using storyboards at all.
Do you use a text editor to write text files? Then use the storyboard editor to write storyboards.
At the end of the day, if you wanted to reverse engineer a storyboard file you could do that, and then hard code your own, new one using what you've learned.
Here's a clue: XML.
Alternatively, ignore storyboards completely, and just programatically create all your views, segues and transitions. That is perfectly feasible.

What is the general structure when coding an iOS project if there is any?

So a few weeks ago I got into Swift and before that I learned a bit Web dev. When learning web development there was always a certain structure to follow for any project. Like specifying where to get the stylesheet from, where to get the JS and that information was put into the head of an html. It is not easy to put my question into words, but is there a general structure for iOS projects? So far I realized that there is always an "import" for example at the beginning of any file to add a framework and then a class. But there is always just one class and all the code goes into that class, why? What else stays always the same for iOS projects?
There are a couple of ways you can approach developing an iOS project. But generally this is what you need to know.
All your UI related designs can be implemented in Main.storyboard file in your project. Here you can create a View Controller and add various UI elements to them like button, labels etc.
To make sure your views look the same across all device screen sizes, you need to use autolayouts which is the process of setting constraints to the UI elements so that they can be resized according to the screen size of the device they are being displayed on.
For each View Controller created you have to assign a class file which is a .swift file. In this class file you have a function by default called viewDidLoad(). This method is executed when the view is displayed on the screen after running the code.
For each UI element in a View Controller you can add IBOutlets and IBAction to their respective class file.
Here are a few links that can help you more:
Tutorial for autolayouts: https://www.raywenderlich.com/443-auto-layout-tutorial-in-ios-11-getting-started
Tutorial for Swift programming: https://www.raywenderlich.com/6338-swift-tutorial-part-1-expressions-variables-and-constants
Get started with iOS: https://codewithchris.com/how-to-make-an-iphone-app/
Some other useful links:
https://medium.com/ios-os-x-development/7-things-you-must-absolutely-do-before-writing-an-ios-app-a8bacf710c57
https://www.raywenderlich.com/477-design-patterns-on-ios-using-swift-part-1-2

Is there anything like AXML for iOS?

In Android, you lay out a view with an AXML file, where you specify the hierarchy of sub views and their relationships, and the OS loads this file and renders the view.
In iOS, there's a NIB file, which is similar in concept, but it's completely human unreadable (in my opinion). You can create this file with the WYSIWYG editor in Xcode, but you can't just type it by hand, because it's immensely complex and impossible to get right.
I find the WYSIWYG editor unwieldy for any but the most trivial layout, and so I'm also finding that in iOS, it's easier to build the control tree in code than to use the NIB file. But the AXML approach seems much easier still.
So, I'm wondering if there's any iOS library that would let me lay out the code in a declarative way (that is, not with a designer), and then create a view from that, with automatic resizing and other conveniences.
The .storyboard format is a simpler format to read, use that instead of XIB files.
It seem like you are coming in iOS development from Android.
But Editing background XML (Back Source) view file is not style of iOS.
Yes you can see that file but Apple want that you design your app by using this two approach only.
How I can say that? Because apple have not provided any document for how to do that (At least I have not come across any).
Design in visual editor (XIB Or Storyboard)
By Using code (Create view and controls and addSubview)
Mostly we use mix approach we use top level and simple design by first one and use detail and complex design by second one.
Storyboard is new and very good one try to use that.

Dynamic Storyboard or Xibs/Nibs

Our company is developing a quite large app for the iPad. Eventually we want to be able to customize the UI per customer (tenant) and maybe even per user (of that customer). We started off in HTML5 but are moving to native.
I've done some reading on downloading XML from the server (or even generated XIB/NIB files) and dynamically adding those to your app.
Now with iOS 5 (and even further in 6) storyboarding is playing a big role.
My questions:
- Would it be better to use (multiple?) storyboards or XIBs?
- What are my options for both if I want to deliver a dynamic user interface?
I'm not looking for a magic pill, nor a discussion on HTML5 vs native, just some information on how I could deliver a dynamic interface and what techniques could help in doing so.
my response to your two questions is:
storyboard is great for scene management; it creates a visual connection between
your various scenes/views. i prefer to use storyboard for as much of my UI as possible.
however, there are elements that i have in some apps that pick up existing or reusable
or otherwise dynamic XIBs. i simply tie these together with my storyboards by loading
the XIBs in code at the location at which i want them. so, my ultimate answer for your
first question is "both", where storyboards are used where possible, and XIBs used for
dynamic scenes/views.
your options for dynamic user interface include at least the following two options (of which, as stated above, i prefer the second):
create all code using XIB files, and perform all UI transitions without storyboards
in code
create as much UI as you know will remain relatively static in terms of relationships
between viewControllers with storyboard, and then load the dynamic parts of the UI
using initWithNibName:bundle:
finally, you can use multiple storyboards if the situation warrants, and this could even apply to dynamic UI, whether it comes from re-usable components created elsewhere in storyboard and maintained separately, or storyboard XML (if you look at storyboard source, it is just XML under the hood) whether acquired from something that generated or wherever. you can even decide to manage your UI with multiple storyboards at the design phase if your app will have several complicated interconnected view-controller scenes (e.g. each tab in a UITabBarController may have its own storyboard, where each storyboard's scene rootController is connected/loaded when a tab is chosen).
StoryBoard all the way! I use to absolutely dislike storyboards, but then i got use to them and now i love them. Storyboards are the way to go.
Layout seems a really powerful framework for developing dynamic GUIs on iOS.
DISCLAIMER: I'm not the author of that framework; the author is Nick Lockwood, who seems to have an account here on SO. I found both this question and Nick Lockwood's Layout framework by googling "ios dynamic gui".
I haven't tried it yet, but it looks really promising.
The project is even hosted at GitHub here, and it has a MIT license.

Resources