Should I learn UIKit or SwiftUI
Table of Contents
SwiftUI feels very young when it first announced last year in WWDC19. It shows a promising future, but it has a rough edge here and there, and it quite hard to predict what it will be like in a year. The year has passed, and here is my thought on Apple's new declarative UI framework SwiftUI.
The gap is getting closer
My arguments around SwiftUI are always like, "You can't do x (UIKit features) in SwiftUI". This year, Apple show an incredible pace of SwiftUI development. The missing UI elements from last year already have a SwiftUI counterpart, e.g., UICollectionView
and UITextField
already have a SwiftUI counterpart of LazyH/VGrid
and TextEditor
.
You can easily support sarunw.com by checking out this sponsor.
Debug 10x faster with Proxyman: Your ultimate tool to capture HTTPs requests/ responses, natively built for your iPhone and macOS. Special deal for Black Friday: Get 30% off for all Proxyman licenses with code “BLACKFRIDAY2024”.
First-class citizen
It looks like SwiftUI doesn't want to be just a view for UIKit anymore. Now, you can write an entire app using pure SwiftUI.
The following is a working SwiftUI app code.
import SwiftUI
@main
struct SwiftUIApp: App {
var body: some Scene {
WindowGroup {
Text("Hello! SwiftUI")
}
}
}
And the code above not just works on iOS, but the same code can make an iPad and Mac app. You can write a multiplatform app entirely with SwiftUI. Seem like the concepts of SwiftUI are far more powerful than I first thought.
Exclusive Deal
WidgetKit, a new framework in iOS 14 for writing a Widget can only write using SwiftUI. This means you can't run away from it, even you love UIKit, it seems like you have no choice, but to also learn SwiftUI.
Is UIKit going to die?
Nope, it is far from over. I don't think Apple has a plan to drop UIKit in the foreseeable future. As working on UIKit for years, SwiftUI feels like magic to me. It can replicate UIKit function with a single line of code (or no line of code since it builds right into SwiftUI). The bad thing about magic is that when things are not going as you want, it is hard to figure out what's wrong, and it might not be possible to fix it. That's when you need to go back to UIKit. UIKit is a foundation of iOS, and Apple still keeps adding new features to it (UICollectionView and UISplitViewController got a lot of cool features this year, you should check it out).
I see UIKit as a secret sauce behind all SwiftUI magic. Both UIKit and SwiftUI have their strength, and Apple picks the right tool for the right job (they use SwiftUI for WidgetKit because it suits the constraint that Widget has right now). I think these two will coexist for a very long time.
Apple put years of experience in their UIKit and tools into SwiftUI. It is enjoyable to work with, and the outcome is phenomenal. Apple can do this because they set up a way to bridge SwiftUI to UIKit, so they know that even when SwiftUI fails to do some tasks, there will always have UIKit there.
You can easily support sarunw.com by checking out this sponsor.
Debug 10x faster with Proxyman: Your ultimate tool to capture HTTPs requests/ responses, natively built for your iPhone and macOS. Special deal for Black Friday: Get 30% off for all Proxyman licenses with code “BLACKFRIDAY2024”.
Conclusion
Here comes the important question. Should you learn UIKit or SwiftUI?
My short answer would be SwiftUI.
And here is my long answer. From all the facts I point out in this article, SwiftUI is ready now. I think in the end you would end up learning both of them.
If you know UIKit, you are forced to learn SwiftUI since it is exclusive to a new framework like WidgetKit. Even not for that reason, I think you probably the one who appreciates SwiftUI the most. SwiftUI can do many great things right out of the box, things that we always want to do in UIKit, but don't have the opportunity and time to do it.
If you know SwiftUI, there would be a time that you want extra customization or hit some roadblock. When the time comes, UIKit will always there for you.
Read more article about SwiftUI, UIKit, WWDC20, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
Become a patron Buy me a coffee Tweet ShareAdd custom SwiftUI view to View Library with LibraryContentProvider
A new way to create a reusable view.
A first look at matchedGeometryEffect
This modifier can interpolate position and size between two views. This is one of the most exciting features for me. Let's see what is capable of in this beta.