ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Migration Of UI To SwiftUI

Home / Article & Blogs / Mobility / Migration Of UI To SwiftUI

Migration Of UI To SwiftUI

By pravallikadamerla inMobility

Apple provides different types of Frameworks such as:

1.UIKit

2.AppKit

3.WatchKit

4.MapKit

5.HealthKit etc;

Apple also has released recently the Swift UI Framework which is

supported in XCode 11.x series

What is Swift UI?

1.SwiftUI framework is  used to build UI faster

2.SwiftUI provides views, controls, and layout structures for declaring your app’s user interface

3.SwiftUI views for displaying text, images, and custom shapes using stacks, lists, and more

4.Apply powerful modifiers to built-in views and your own views to customize their rendering and interactivity

5.Share code between apps on multiple platforms with views and controls that adapt to their context and presentation

6. You can integrate SwiftUI views with objects from the UIKit, AppKit, and WatchKit frameworks

7. You can also customize accessibility support in SwiftUI, and localize your app’s interface for different languages, countries, or cultural regions

8. Animations are built using simple commands that describe the action you want to see

9.SwiftUI is a lot faster in loading JSON etc

And many more….

What is UIKit?

1.UIKit is a programming framework that defines interfacing elements (such as labels, buttons, navigation Controller etc )

2.Build user interface using StoryBoards which makes it slower compared to Swift UI(as it is a declarative user interface)

How to migrate UI to Swift UI?

Make sure you are compatible with

1.macOS  Catalina

2.xcode 11

Now open the old project and start creating empty SwiftUI file, Update Appdelegate

You need to add scene lifecycle ios13 is now focusing on

UIWindowSceneDelegate as start point(previously it was

UIApplicationDelegate)

Need to implement inside the app delegate to pass the control to

UIWindowSceneDelegate

 

// MARK:**UISceneSession Lifecycle**
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: “Default Configuration”, sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}

Create a MainView.swift

 

import SwiftUI

@available(iOS 13.0.0, *)
@available(iOS 13.0, *)
struct MainView: View {
    var body: some View {
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
    }
}

@available(iOS 13.0.0, *)
@available(iOS 13.0, *)
struct MainView_Previews: PreviewProvider {
    static var previews: some View {
        MainView()
    }
}

 

Create UIWindowSceneDelegate

Create an empty swift file called SceneDelegate.swift with the following content:

 

import UIKit
import SwiftUI

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Use a UIHostingController as window root view controller
        let window = UIWindow(frame: UIScreen.main.bounds)
        window.rootViewController = UIHostingController(rootView: MainView())
        self.window = window
        window.makeKeyAndVisible()
    }

    func sceneDidDisconnect(_ scene: UIScene) {
        // Called as the scene is being released by the system.
        // This occurs shortly after the scene enters the background, or when its session is discarded.
        // Release any resources associated with this scene that can be re-created the next time the scene connects.
        // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
        // Called when the scene has moved from an inactive state to an active state.
        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
    }

    func sceneWillResignActive(_ scene: UIScene) {
        // Called when the scene will move from an active state to an inactive state.
        // This may occur due to temporary interruptions (ex. an incoming phone call).
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
        // Called as the scene transitions from the background to the foreground.
        // Use this method to undo the changes made on entering the background.
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
        // Called as the scene transitions from the foreground to the background.
        // Use this method to save data, release shared resources, and store enough scene-specific state information
        // to restore the scene back to its current state.
    }

}

 

 

Find there the key for your Storyboard and completely remove it from your Info.plist:

<key>UIMainStoryboardFile</key>

<string>STORYBOARD_NAME</string>

Now you’ll need to add the following:

<key>UIApplicationSceneManifest</key>

    <dict>

        <key>UIApplicationSupportsMultipleScenes</key>

        <false/>

        <key>UISceneConfigurations</key>

        <dict>

            <key>UIWindowSceneSessionRoleApplication</key>

            <array>

                <dict>

                    <key>UILaunchStoryboardName</key>

                    <string>LaunchScreen</string>

                    <key>UISceneConfigurationName</key>

                    <string>Default Configuration</string>

                    <key>UISceneDelegateClassName</key>

                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>

                </dict>

            </array>

        </dict>

    </dict>

This code will tell your application that you now want to launch with your

scene delegate.

So now we are ready!

References:

https://developer.apple.com/documentation/

https://nikrodionov.com/project-migration-to-swiftui/

 

 

SwiftUI
91
Like this post
4 Posts
pravallikadamerla

Search Posts

Archives

Categories

Recent posts

International SEO: How to Get Website Traffic from Other Countries

International SEO: How to Get Website Traffic from Other Countries

Top Reasons to Use Salesforce Consumer Goods Cloud

Top Reasons to Use Salesforce Consumer Goods Cloud

What should Gay Pride Month mean to an organization?

What should Gay Pride Month mean to an organization?

10 Amazing Benefits of Salesforce Marketing Cloud

10 Amazing Benefits of Salesforce Marketing Cloud

How to Set SMART Goals for Employee Performance?

How to Set SMART Goals for Employee Performance?

  • Previous PostDisplaying standard report data in Lightning component
  • Next PostPardot : Understanding Layout Templates

Related Posts

Leave a Reply (Cancel reply)

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

*
*

ABSYZ Logo
  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

ABSYZ Software Consulting Pvt. Ltd.
USA: 49197 Wixom Tech Dr, Wixom, MI 48393, USA
M: +1.415.364.8055

HYD – India: 6th Floor, SS Techpark, PSR Prime, DLF Cyber City, Gachibowli, Hyderabad, Telangana – 500032
M: +91 79979 66174

2nd Floor, 91Springboard, Padmavathi Complex, 80 Feet Rd, Koramangala, 8th Block, Bengaluru, Karnataka-560095.
+91 8886332345

Copyright ©2020 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT