UIKit and SwiftUI

Hi everyone, can anyone explain me the difference between SwiftUI and UIKit?
Thank you.

Answered by Claude31 in 704090022

There are a lot of differences. SwiftUI and UIKit are not at the same level.

UIKIT "simply" provides API to access all the func to manage UI. Developer is in charge of the UI logic: when something changes here, update UI there. You can use notification to do it, but it is your responsibility. You design the interface either graphically in storyboard (WYSIWYG) and connect to code through IBOutlets. So you manage the state of each view and write code to redraw according to this state.

SwiftUI relies on UIKit in fact. It asks you to build the interface in code and not graphically. But it provides the layer to manage all this UI updating logic: a view is automatically updated when its state changes.

Hopes that's clear enough.

Accepted Answer

There are a lot of differences. SwiftUI and UIKit are not at the same level.

UIKIT "simply" provides API to access all the func to manage UI. Developer is in charge of the UI logic: when something changes here, update UI there. You can use notification to do it, but it is your responsibility. You design the interface either graphically in storyboard (WYSIWYG) and connect to code through IBOutlets. So you manage the state of each view and write code to redraw according to this state.

SwiftUI relies on UIKit in fact. It asks you to build the interface in code and not graphically. But it provides the layer to manage all this UI updating logic: a view is automatically updated when its state changes.

Hopes that's clear enough.

So UIKit is used by the storyboard in Xcode and SwiftUI is used by the normal mode. Right?

So UIKit is used by the storyboard in Xcode and SwiftUI is used by the normal mode.

Not exactly. Storyboard is just a drawing. You connect to code with IBOutlets and the code uses UIKit. But you could write a complete program without storyboard, creating the UI entirely in code (as you do for alerts for instance). However, to use storyboard, you have to use the UIKit "app cycle".

In SwiftUI, you cannot use Storyboard, and all the UI is generated from code. But Preview let you see it and even interact with it and see where is code related to the object.

What to keep in mind is that difference is in the way state change in views are handled. In UIKit app cycle (MVC model), you keep state in model and use this state to update views, With SwiftUI (MVVM Model), system manages the automatically these state changes.

This should give more details:

https://stackoverflow.com/questions/19444431/what-is-difference-between-mvc-mvp-mvvm-design-pattern-in-terms-of-coding-c-s

Understood! Thank you.

UIKit and SwiftUI
 
 
Q