SwiftUI Code: Pros and Cons to Be Aware Of

    Apple designed SwiftUI to give programmers a better way to code applications for the company’s platforms. It shouldn’t be confused with Swift itself — a programming language that is used mainly for iOS and MacOs development. Instead, SwiftUI is a framework that can be used together with other tools such as AppKit and UIkit to build interfaces faster and with less code.

    Nevertheless, it’s not without drawbacks that should be considered before you decide to implement it in your project.

    Advantages of coding with SwiftUI

    SwiftUI code is more concise and readable, which translates into a better development experience. This, in turn, helps to iterate and complete projects faster.

    Learn how we build industry-leading applications with Swift and SwiftUI
    Read about our process
    • Declarative code. Declarative programming is an approach where you specify what you want the app to do, rather than how it should do it. This is in contrast to imperative programming, where you provide step-by-step instructions. Declarative code tends to be easier to read, more modular and less prone to errors.
    • Compatibility with UIKit and AppKit. UIKit is a framework used for developing iOS and iPad apps, and AppKit provides a library of interface elements. Many existing iOS apps already use these tools. Since SwiftUI is compatible with both UIKit and AppKit, they work seamlessly together on all Apple platforms.
    • Improved development experience. A more robust implementation of live preview available through Xcode, being able to drag and drop UI components into a canvas that displays the app, and an automated approach to handling layout — all of it leads to a more efficient workflow.
    • Faster development time. These quality-of-life improvements mean faster iterations, which shortens time-to-market (TTS). We can also use tools such as SwiftGen — a tool that allows creating secure access to images, fonts, color palettes, etc. This significantly speeds up the monotonous, but time-consuming tasks, for example, changing the color of elements or replacing icons reducing development time by up to 20%.
    The Surf team has created custom tools to help developers complete projects faster
    Browse case studies

    Disadvantages of coding with SwiftUI

    At this point, SwiftUI might seem like a no-brainer, but it’s not perfect. Most of this framework’s disadvantages stem from the fact that it’s relatively new — only 4 years old at the time of writing this.

    • It may be hard to find talent. The pool of developers who have experience with the framework is still a bit limited, so bear in mind your long-term capability to find skilled professionals. 
    • There’s a lack of supplied libraries. Many developers still find that built-in libraries limit their ability to work efficiently, but this is only true for certain versions.
    • Poor compatibility of versions. The framework is still at a stage where development patterns are constantly being depreciated and updated. For example, Apple recently changed the way navigation bar titles are set. These changes require developers to constantly come back and refactor old code.

    Wrapping up

    Because SwiftUI is relatively new, it might be a bit rough around the edges. But it also means that the framework is constantly evolving.

    Recently, developers have added a better way to work with lock-screen widgets, a more robust Grid layout implementation, a new method for drawing data-driven graphs and charts, and more highly beneficial features.
    Combined with time savings, all of it makes this framework a serious contender for your new project.