Topics In Demand
Notification
New

No notification found.

Declarative Programming - a new way of App design for Apple platforms
Declarative Programming - a new way of App design for Apple platforms

April 3, 2020

7

0

Declarative programming is the way of describing logic with self-explanation which makes anyone understand the code easily. This helps with code readability and the knowledge transfer becomes easier.

Currently, Objective C and Swift are the languages, we’ve been using for developing iOS applications. Now, Apple comes with the new declarative approach called SwiftUIwhich is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift.

In this, we can easily write code and check the preview of UI instantly. Likewise, we can make changes in UI and it will reflect in code, as well.

In the existing approach, Swift/Objective C code statements vary for each platform. i.e, iOS application code is varied from the Mac application code. But declarative programming makes it simpler to adopt the code for all of Apple’s platforms.

All views are extremely lightweight so there’ll be more performance improvements as compared to the existing approach for creating views — because it avoids the use of heavily used subclasses and memory allocations.

Also, it composites all subviews in a single entity during the layout of a screen so each view becomes distinct and thus, makes way for observing state changes and the ability to render only if any state changes.

  • Apple’s existing UIKit’s core design philosophy is the inheritance
  • SwiftUI’s composition

The major advantage is that it can translate views to visual interface elements according to platforms like iOS, macOS, watchOS, tvOS.

For example, a Toggle view can be visualized differently on each Apple’s platform like below.

 

Here you can see the toggle button size and layout differs from iOS/watchOS, macOS and tvOS. This is based on each platform’s controls and in accordance with its screen size.

Likewise, it will properly adapt to changes in colors, padding, size alignment, etc. based on the platform.

For example, a button might be small in an iPhone and the small code will change the button size according to the iPad screen.

Pros:

  • We can visualize UI for changes without the need to recompile the whole application
  • Reduces screen designing time
  • Enables better integration between Developers and Designers
  • Improves the speed of development
  • Views can adopt properties according to different Apple’s platforms (iOS, MacOS, watchOS, tvOS)
  • It provides Automatic support for Dynamic Type, Dark mode, localization. So, no need to write any code specifically for Dark mode
  • It also provides an option to use existing architecture UIKit by using UIHostingController
  • SwitUI replaces storyboards and auto layout, so merging code becomes easier when compared to fixing storyboard conflicts

Author: Balaji Ramakrishnan
Stream: Mobile


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


Your Digital Transformation partner

© Copyright nasscom. All Rights Reserved.