SwiftUI Intro
Introduction
Apple has announced a big changing in designing the app in recent WWDC (2019). Apple has come with new idea of “declarative UI” named as SwiftUI. Its better than imperative UI in many ways. We will discuss it later. SwiftUi will be useful from swift 5
What is SwiftUI
SwiftUI is the latest framework for front-end of IOS. Apple has adopted some conventional web development concepts.This is definitely an awesome move because programming interface and managing states are drastically easier than before. And the best part of this improvement is that one can integrate UIKit and SwiftUI smoothly.
Why apple do this
Some developer says on lite notes that apple likes to keep busy its developer. They make major changing and either invent or adopt new pattern in programming. Swift 5 is one of them. Swift 5 came with decorative UI concept. I think apple is inspired by success of react-native and flutter and it wants to adopt package concept of react. I can claim this because SwiftUI follows state maintain concept.
How difficult is to work
It’s not too much issue for react developer to adopt this concept easier because they will be familiar with declarative UI concept but for sure, it may be arduous for native swift developer. I am native swift developer as well and I faced some issues that are listed below:
Long sentences: Swift UI use dot notation for properties that makes sentence longer in custom views and it creates difficulty in reading.
Readability: Imperative UI has graphical option to understand UI better.You could select and check every property easily in Imperative UI.
State maintaining: Even though its feature in swiftUI but it creates some confusion in starting to debug the states.
View and controller coordination: Handle ui changing in code and debug in design file
Pods problem: I amp and libraries person. I believe that its better to use other person’s work rather than re-invent the tyre. It helps to complete fast. I use many custom view’s libraries and pods file.And now in latest swift, either I have to replace them or update them. Many libraries have been obsolete after swift 5
Advantages of SwiftUI
State maintainability: If we have one screen with one Boolean property that affects the UI, we have two states: the Boolean might be on or off. If we have two Boolean, A and B, we now have four states: And if it effects on button state, than it will be more difficult to hear. In Swift UI,We don’t need to write code to move between those two states by hand – that’s the ugly, imperative way of working. Instead, we let SwiftUI move between user interface layouts for us when the state changes.
Cross-platform SwiftUI acts as a cross-platform user interface layer that works across iOS, macOS, tvOS, and even watchOS. This means you can now learn one language and one layout framework, then deploy your code anywhere.
Open new gates
Apple always open new doors for learning of developers. New libraries will build, new work on cocoapods will be done. Big changing comes with big opportunities.