What is SwiftUI and why you need it

After a few years, maybe in a year or two, Apple operating systems will change dramatically inside. And, of course, will follow external changes, and hopefully the system will be better. A small number of fragments of this future are tested in macOS Catalina and in the latest versions of all operating systems of Apple. And these fragments are impressive, like magic, admirable and a little buggy. This article is about one of these fragments. To understand, but if you want to understand, also read.

Application development will soon reach a new level

What is SwiftUI

The rumors that Apple that’s right, almost recently, will release absolutely fabulous 16.5-inch MacBook Pro “without frames around the screen”, with a special keyboard, not subject to “butterfly effect”, will soon be a year. I wonder what happens before and what new tricks we will meet in this laptop? And what kind of special keyboard? Scissors or something again, something special, original and best? And again, exactly a year ago, Taiwanese analysts report about the mass production of these MBP that has become legendary even before the birth, and monitor the delivery of different accessories to them. Last time, however, proved that all these components were for some other laptop – but intelligence and Analytics risky profession. Whether it’s a MacBook Pro at all? I think not. If you think otherwise, share in our Telegram chat.

But the fact that Apple is working on a new “filling” operating systems of the company, and some of these developments are already available for third-party developers in Xcode 11, and these pieces of Apple for the first time in its history, uses good old Swift differently than before – as if no one heard. Reactive and declarative programming for a long time, and are used in industry for decades – but Apple, just like old times, uses them differently. Do not be surprised if after a couple of years, it is “Apple” the embodiment of all this will be a role model, yet may the ill and then dying with laughter, watching the vain attempts of “lady of whims” to cultivate in his glass Palace “ancient innovation”.

SwiftUI at the conference WWDC 2019

We can not say that about SwiftUI no one writes. He admired. To perfection for him (“UI” stands for and means “user interface”, it means “he”) has to evolve and develop, but conceived it is so beautiful and original that to remain indifferent is not obtained. It equals with the dirt (enumerating the functions which are in XAML, Flutter and other analogues, but not in the “newborn”). It is called the replacement AppKit (macOS) and UIKit (for iOS and iOS-like systems), but it’s not true. SwiftUI is a separate framework and an integral part of the Xcode 11, he undertakes part of the functions of AppKit and UIKit, while using the functions of the AppKit and UIKit, for example, display interfaces and user interaction. According to one of the engineers of the group SwiftUI it is temporarily in the future in the place of AppKit or UIKit will be something else.

But the way of life of Interface Builder (IB) is coming to an end – SwiftUI does the same as IB, only more interesting and more effective. In 1986, a PhD in computer science Jean-Marie Hullo wrote a program InterfaceBuilder (in LISP) for the company ExperTelligence. And LISP is, if you do not know, “the declarative version of Fortran”. Once, in 1987 or in 1988, Jean-Marie brought in the NeXT office and introduced to jobs. In 1988 NeXTSTEP 0.8, which consisted of IB written in Objective-C. IB used to develop the world’s first browser, WorldWideWeb, and so much more – very well-deserved man. The last update happened 8 years ago in 2011. At WWDC 2011 promised a lot of things in it that showed on the sidelines looked less fantastic than Canvas SwiftUI, but for that time it would be great – alas. These features never came to IB and will not come.

IB to 2011 and was updated infrequently, and since 2008 the number of users Xcode grew rapidly, and almost 90% of users wrote programs for the iPhone OS (as it was called iOS), and IB in their work used every third. It happened to me. To write for iPhone OS began long before (for six months) before the first beta of the iPhone SDK, and Apple traces IB (a file with the Xib extension) was not. Steve promised that the SDK is sure to be IB, but to get this tool to work with a mobile OS that was harder than to move it from LISP to Objective-C. In the first beta SDK, it was not. Until the iPhone SDK 2.0, he desperately buggy, and it was then that the people were accustomed with the new system, gained experience and acquired habits. IB for iPhone buggy for a very long time, almost until 2011. MacOS also write some interfaces in the code manually – I only know of one such eccentric. There IB also not without glitches, but they are few.

Using Interface Builder in Xcode

As a result, user interfaces programmers iOS and iOS-like systems write either via IB or in the source code. As a user of IB with almost 20 years of experience, saying: alas, SwiftUI really “cooler” than IB. This is an adequate replacement. For depicting the interfaces in source code SwiftUI even cooler, because now (in real programs SwiftUI as yet hardly used) in order to position the screen element of the interface, let it be a text string, any inscription, the programmer must:

  • to create an object of the appropriate type;
  • to calculate the coordinates specifying the position of the object on the screen;
  • to place the object on the screen;
  • to set the value of the object;
  • to set the attributes of text (multiple lines, typically the font, style, color, etc.)

This is one of the most simple objects – creating tables (list) manually may take more than one hundred non-trivial lines. It is believed that in every hundred lines of new code, as a minimum, must be two mistakes that are not identified during testing and will show up only in the hands of the user. When you increase the number of lines N times the number of errors increases in N squared time. This joke is a joke share. By the way, if you don’t know what is imperative programming, you just saw it “in person”.

In SwiftUI uses a declarative paradigm in which this detail and all these thousands of lines are not needed. The programmer specifies what and how relative to other elements must be displayed on the screen (everything is immediately displayed on the screen Canvas will look like in a real program), and in addition, Apple engineers have added to this already impressive picture of hundreds of crazy but very useful tricks. The result is magical – I look forward to when all this will be implemented in the final version (after a year or two).

Leave a Reply

Your email address will not be published. Required fields are marked *