Swift Build Dynamic Apps - ios

I want to develop an app, which can be modified programmatically. In my config.swift file, I save the main settings for my app. For example: If I want to create 5 textfields, I set a variable for that (in config.swift) and this will create me five textfields. This works perfectly! But as I do everything programmatically (e.g. adding textfields), I don't have the advantages of the visual storyboard. Is there a way to create UIElements dynamically, without dispensing the advantages of a storyboard?

Everything you can create in the Storyboard can be created in code. When you create your Storyboard it is set with that structure, but when you create it programmatically it´s more dynamic and you can create elements "on the fly".
The main advantage with the Storyboard is that you get a visual overview of your layout. Up to you to choose what suits your needs best.

Related

creating a scrollview with data coming from database and variable number of elements for ios

So I was trying to create a sample ios application. As I am designing the app UI with the storyboard (and not coding), I find Xcode really hard to understand.
what I want to do is I added a scrollView to the view controller. now what I want to do in the scrollView is simple.
I want my scrollView to have buttons (vertically stacked) and it does some action on the basis of the data it is getting from the database. let's suppose it is getting links from the database and on a click of those buttons those links open. now the data may contain 10 links, or 20 links .. basically, we want it to be according to the database.
now if I was designing the UI programmatically it would look something like
ScrollView{
for loop...{
button("for example name coming from the database"
}
}
or atleast this is what I know of.
so how to do the same with storyboard ?
like we first take it's refernce to the uiViewController class.. and then ?
You need to add buttons programmatically if they are created dynamically depending on external non static data. Create new UIViewContoroller class and implement it with connecting storyboard file, the easiest would be to add buttons inside some kind of UIStackView which is inside scrollview imo, or by using UITableView if there are significant number of links to display.

create a strings file for a custom storyboard

I am localizing my app, and I have a custom storyboard I created called Into.storyboard. When I added a language to the app, it gave me an option to create strings files for Main.storyboard and LaunchScreen.storyboard, but not for my custom storyboard. How do I create one so that it automatically fills in the object IDs like it did for the other two storyboards? Thank you
At the right side inspector you can find button localize. Press it and choose languages.
Example

Replacing Swift Storyboard with New, Imported Storyboard

Having completed the functionality in code, my app required a full redevelopment of the original interface design. That was done by another team member, in a separate project.
It seems obvious that importing the new design as a storyboard file and using that is the next step. The original storyboard has a number of segues, I'd like to just replace the UI contents of that with the contents of the new storyboard (and then reconnect everything).
I'm not sure how to do this. What's the best method?

Storyboard is very slow

So I've been working on a project for a while that has so many view controllers, but I notice that now when I try to do a single edit in any view , storyboard hangs, or become unresponsive . what would be the solution for this issue ? is it possible at my current state to split up the whole storyboard into smaller ones ? and will that resolve the problem ? I'm using Xcode 9.3
Yes. You can have more than one storyboards in one project. In fact that's the preferred way to manage very large projects. To create more storyboards go to File Menu > New > File... and then select Storyboard from the User Interface section. Doing this should resolve your issue. However, if the issue still persist you can consider taking out the specific user interface into its own .xib file.
Update:
If I were in your position I would have considered using .xib files to create my user interface instead of using storyboards. Storyboards do have their advantages but there are some cons too if you use them. Like:
If you work in a team you will run into merge conflicts more often because someone else made a change in the storyboard.
I am still not a Guru in S/W design but, to me it seems like Storyboards violate the Single Responsibility Principle of S/W design.
You won't be using Segues in complex ui flows anyways so what's the point of having every thing in one file.
You won't be able to reuse your UITableViewCells interface. Prototype Cells are a good idea but if you have a UITableViewCell which is used in more than one UITableView you will have to replicate the UI in Storyboard.
In my experience, in a more complex and large project having everything in one Storyboard makes it even hard to comprehend the UI/UX flows as Segues from every view controller seem to connect with every other view controller to the point where it just stops making sense at all.
Yes, it is best practise to distribute viewConrollers into multiple storyboards so that you can open it quickly but it can lead your time to manage each storyboard identification programatically while accessing into code.
Otherwise, you can set storyboard View as : iPhone 5C so that it can load little bit faster than bigger devices.
Refer:

Is it necessary to create all views in storyboard in the beginning?

I am new to iOS and have recently finished some classes.
Now, I'm onto my first app with Swift. I wanted to know:
Is it necessary to define all views/screens in the storyboard right in
the beginning, with proper navigation controllers?
What is better, define all in the beginning or keep adding as need
arises in the future?
Keep adding as needed.
You'll always be finding or coming up with new features, and at times you'll need to insert view controllers between other view controllers (adding an extra step, for example).
Within view controllers, you'll also find the need to put items into containers. That's where clicking the item/s (selecting them), and going to the menu, selecting "Editor" and then "Embed In" comes in really handy. For example, you may want to put a series of items into a scrollview after you've already laid them out properly, because they don't display properly on an iPhone (and you had done all of your testing in Simulator on an iPad first).
No it's not, you can create all views programmatically without using a storyboard at all. Its's just your choice what works better for you.
First of all, you can use storyboards for your UI (and navigation), use .xibs (only UI) or create everything programmatically. Each of these has its pros and cons. Also you can mix and match all these. For example have a storyboard, some views with .xibs and some views created programmatically all in the same project. You just have to choose what fits best your needs.
You don't have to create everything in the storyboard right in the beginning. Create only the views you need to start coding and then add more views as you progress your app development.

Resources