I have been working on iOS development for more than 4 years. I have written OC and Swift, and I have made at least 7 or 8 apps for the AppStore, including those that can not be put on the AppStore in mainland China and those that I helped my friends to make together, so there should be nearly 10 apps altogether. (Solid UI engineer +API engineer 😂😂😂)

In these years, STEPPING on the shoulders of predecessors, I have also learned some tools or technologies that can improve development efficiency. Recording them can be regarded as both a summary and a share.

Let’s start with a few scripts

Storyboard color script

Color script for the storyboard, is written in Python. Add this script to Build Phases

Storyboard custom colors are only supported for iOS11 and up, so this script helps us customize colors for iOS11 and up, which is really useful for me as a heavy storyboard user. After the new color is added, the first compilation will be red, which is ok, because the script is still running, and the second compilation will be ok.

Second, R.s wift

It is inevitable that some strings, images, fonts, colors, etc. in our code are hard-coded, error-prone and difficult to manage,R.swiftThe Github home page has an example.

let icon = UIImage(named: "settings-icon")
let font = UIFont(name: "San Francisco", size: 42)
let color = UIColor(named: "indicator highlight")
let viewController = CustomViewController(nibName: "CustomView", bundle: nil)
let string = String(format: NSLocalizedString("welcome.withName", comment: ""), locale: NSLocale.current, "Arthur Dent")
Copy the code

With R.swift, it generates a comparison table that is easy to manage, code prompt, and error-proof to use.

let icon = R.image.settingsIcon()
let font = R.font.sanFrancisco(size: 42)
let color = R.color.indicatorHighlight()
let viewController = CustomViewController(nib: R.nib.customView)
let string = R.string.localizable.welcomeWithName("Arthur Dent")
Copy the code

Note that this file must be added to gitignore, otherwise it is prone to conflict.

Third, the UI

Script tools to introduce these two kinds of, next to introduce a native Apple View- UIStackView, recently read the Weibo, found that even some big guy, it seems to often use error, especially with UIScrollView use. UIStackView is a container view that expands itself according to the contents of the container. It has two layouts, one horizontal and one vertical, which will become very common in future SwiftUI. So, unused friends should be familiar with it as soon as possible. StackView is also a good tool for cutting UI as we get used to it. Another nice thing about UIStackView is that if a view needs to be hidden, we just set it to hidden, and UIStackView automatically sets its height to 0, so we don’t have to manually pull the constraint and change it.

UIStackView with UIScrollView can basically achieve most of the non-list pages, and ScrollView is used to prevent the display of the screen beyond the full and add apple’s native up and down sliding effect to enhance the user experience. But there’s a caveat to using UIScrollView in storyboard, UIScrollView is a container view, so we can’t just set the top, bottom, left, and right to 0 because the content doesn’t exist yet. Xcode will tell us that contentSize is missing.

So, the next step we add contentView, need to pay attention to, the contentView high set respectively how many wide, some students may take it for granted, respectively, set about from the ScrollView fluctuation of 0, ScrollView is only a container view, The width and height of its content should be supported by the contentView, so the contentView needs to have a width and height of its own. So if it’s a scrollView scrolling up and down, it should have a fixed width, like the width of the screen, so the width of the contentView is the width of the screen, and the height is spread by the content, so the scrollView should be 0.

As you can see, I’m going to set the height to 2000 for the time being, so Xcode won’t give you an error. In real life, the height is usually not fixed, as long as the View inside the contentView is self-adaptive, so if I put a Label inside that has only one line of content, it won’t scroll.

If I set the Label to multiple lines, it’s going to spread itself out, and the scrollView is going to scroll.

So there’s a lot of possibilities for scrollView and stackView, except for the obvious tableView, and basically everything else can be done with scrollView and stackView. Of course in swiftUI, tableView is also stackView.

UI part, proficient in the use of these two, most of the design draft can be basically achieved, and then learn a bit of separation, packaging, reuse is relatively high.

Four, architecture,

Next, I would like to talk about the structure. In my opinion, there is no good or bad structure, only suitable or not suitable. Many architectures are also deified. IOS development should be most familiar with MVC, MVC is not bad, the so-called Controller bloated, most of the probability is that we write too bad code, did not follow the seven PRINCIPLES of OOP.

1. Learning costs

MVC is old, but let’s face it, it’s easy to use, and it costs almost nothing to learn. I used to get used to the front-end Redux architecture, which is called Reswift in iOS. I have to admit, there was some learning cost. At that time, several of my colleagues had the same reaction. Of course, it also had something to do with the fact that we were not familiar with Swift. However, there is no doubt that the learning cost of the team is relatively high, and if it is a small project, there is no need to open another structure, and the benefits are not proportional to the efforts.

2. Add code

Too much new architecture can lead to too much code, although some of the side effects can be eliminated by using template code (see my previous post on template code).How can iOSer become Iron Man and build its own code army), but cannot completely eliminate, will inevitably increase the amount of code. Because one of the roles of architecture is to unify team code, in order to enforce uniformity of code, there is often code that standardizes code. Such as Reswift’s forced data flow. Of course swiftUI will be born with data binding and that won’t be the case.

3. Standard code

Of course, we have to admit that architecture makes it easier for us to standardize team code, so that when a team writes the same code, it will be easier for other members to take over later. And when you have a bug, it’s easy to locate the problem, because UI to UI, logic to logic, data to data, all separated.

A good architecture is certainly convenient for programmers, wouldn’t be added for programmers, so, in a long period of time, after many attempts to tend to take its essence and discard the dregs, the team will settle down one is suitable for their own architecture, could neither MVC, nor MVVM, nor is it a story, or is the MVC and MVVM, Or the story.

Having said so much, this essay has no specific theme, neither a summary nor a reflection. Every iOSer after 4-5 years, should need to think about which way to go forward, is to dig deep or expand their skill package, or how to choose the depth and breadth of technology. Although the two need to be shoulder to shoulder forward, but always have a focus, or they often end up in the middle. I recently started studying Python in my spare time. Why python? Scripting languages help us improve efficiency in later development, as you can see in the scripts above. I have studied flutter and swiftUI before. I have had a preliminary understanding of flutter and written several pages, including network loading data and page routing Settings. I will continue to study the depth and breadth of knowledge when I have time later. A lot of the problems that you are hard to understand now actually depend on cognition, lack of cognition will be hit by dimension reduction. The depth of knowledge I need to know is that one thing, but if we do, it may take us a long time, and many of us will never get there. So, relatively speaking, broadening the scope and increasing cognition is an easy path for us ordinary people, and scientists are not the destination for all of us.

Of course, there is a very important point in my choice of Python, that is, God Yang taught himself Python, I can learn from him when confused, compared with looking for information from the Internet, there is a god can help you answer, especially in the early xiaobai, it is a happy thing, ha ha.