Build class-apart UI on apple devices using SwiftUI

Developing exceptional UI using Declarative UI in SwiftUI

Want mind-blowing user interfaces on premium apple devices? Looking for an option that is easy to use and learn? SwiftUI is your solution. SwiftUI is the simplest way one can build user interfaces across all platforms. 

SwiftUI was launched at the Worldwide Developer Conference (WWDC) 2019. Soon the developers began to leverage the published APIs that helped them adopt newly introduced SwiftUI features efficiently.

In WWDC 2020, Apple unveiled a few more APIs, which will help develop complete apps using SwiftUI without adding any UIApplicationDelegate or SceneDelegate to the project.

Earlier in iOS 13, the developers would write the code below in SceneDelegate.swift file to attach SwiftUI View to the app:

After introducing XCode 12 and iOS 14, developers agreed on removing AppDelegate and SceneDelegate from apps.

Here is the latest Project Template Structure of XCode 12,

Now, you can define and attach your app using the  code mentioned below in MySwiftUIApp.swift file:

So, ContentView will be displayed to the user once the app launches.

Let’s start adding some Text to the ContentView.swift file:

Its preview will look like below:

SwiftUI also allows you to modify text and other information and cons by writing the code below; we will make separate strings for each view to make the code look more organized, readable, and testable.

This will give an output as below:

We can also add an image as a background. See below:

The output will be the same as:

In conclusion, one can build apps using SwiftUI easily.

Here is a comparison chart between the features of UIKit to SwiftUI; this will make it easier for you to determine various resources and identify which amongst the two matches your requirements.

UIKit SwiftUI Note
UIViewController View  
UITableViewController List Alternatively we can configure LazyHStack & LazyVStack with ScrollView
UICollectionViewController UICollectionViewController Introduced in iOS 14.
UISplitViewController NavigationView  
UINavigationController NavigationView  
UIPageViewController TabView Introduced in iOS 14 as style of TabView
UITabBarController TabView  
UIAlertController Alert  
UILabel Text Label  
UITabBar TabView  
UITabBarItem TabView Available as .tabItem with TabView
UITextField TextField SecureField is available for password – secure entry
UITextView TextEditor This feature is introduced from iOS 14
UITableView List  
UINavigationBar NavigationView  
UINavigationItem ToolbarItem This feature is introduced from iOS 14
UIBarButtonItem NavigationView  
UICollectionView LazyVGrid and LazyHGrid This feature is introduced from iOS 14
UIStackView HStack LazyHStack
UIStackView VStack LazyVStack
UIScrollView ScrollView  
UIActivityIndicatorView ProgressView with CircularProgressViewStyle This feature is introduced from iOS 14
UIImageView Image  
UIPickerView Picker  
UIButton Button Link
UIDatePicker DatePicker  
UIPageControl   This feature is introduced from iOS 14. Available as PageTabViewStyle style of TabView. Also with modifier named .indexViewStyle.
UIProgressView ProgressView This feature is introduced from iOS 14
UISegmentedControl Picker Available as SegmentedPickerStyle of new Picker of SwiftUI
UISlider Slider  
UIStepper Stepper  
UISwitch Toggle  
UIToolBar NavigationView with .toolbar This feature is introduced from iOS 14
MKMapView Map import MKMapView to use default UIKit Map View

Pros of SwiftUI:

  • Easy to adapt, cleaner, and simpler code.
  • Can be clubbed with UIKit using UIHostingController and UIViewRepresentable.
  • Easier theme management. Switching between themes is less complicated.
  • SwiftUI comes with the power of two-way binding with BindableObject, ObjectBinding, and the combined framework.
  • Live preview is accurate. With an increasing demand for cross platforms and advanced platforms, it is a much-needed feature to attract developers.
  • SwiftUI does not require Storyboard/Interface Builder. Canvas replaces it.
  • SwiftUI does not require Storyboard/Interface Builder. Canvas replaces it.

Cons of SwiftUI:

  • Support starts from iOS 13 and Xcode 11. No backward compatibility. Also, some of the components introduced in iOS 14 may not work with the iOS 13 version.
  • No or less forum or developer support, less equipped conflict handling will create weak architectural issues.

Are you thorough with how you can use declarative UI to create a mobile application by leveraging SwiftUI? If you have any queries, get in touch with an expert at DEV IT now.


The following two tabs change content below.

Milan Manwar

Senior Software Developer (Mobile) at Dev Information Technology Ltd.
Milan Manwar has around 8 years of experience in developing apps for Apple Platforms. He works at DEVIT as Project Lead. His area of expertise includes application development for iOS, iPadOS, watchOS, macOS & Android as well. He is an expert in Swift, SwiftUI, Ionic Framework along with Flutter. He has made his place in the industry through his valuable contributions to the developer community. He loves to keep himself updated with the latest mobile technologies.

Leave a Reply

Your email address will not be published.