In the world of iOS development, it's very common to hear developers talk about how much they love SwiftUI because it's a lot easier than UIKit, but what does that really mean in practice? Let's check out an example! 😍
I've created two identical apps in SwiftUI and UIKit, each one just shows "Hello, World!" on screen.
Here are all the steps I needed to take to programmatically create this view in UIKit:
1️⃣ Create the property that will hold the UILabel
2️⃣ Change the background color of the view so the text is visible
3️⃣ Assign the UILabel a value and set its text property equal to "Hello, World!"
4️⃣ Add the label as a subview to the view
5️⃣ Set translatesAutoResizingMaskIntoConstraints on the label to false
6️⃣ Set constraints on the label to keep it centered regardless of screen size and device orientation
Here are all the steps I needed to take to create this view in SwiftUI:
1️⃣ Write "Hello, World" in a Text view like this: Text("Hello, World!")
Not only does this show the text on the screen, but the text will automatically stay centered regardless of screen size and device orientation AND we get dark mode support out of the box. Turning dark mode on in the SwiftUI app makes the text white and turns the background black, but turning on dark mode in the UIKit app only makes the text white and does not change the background color to black. While this functionality is possible in UIKit, it just takes more code.
To summarize: Both frameworks are awesome for different reasons, but UIKit definitely requires more code to perform the same tasks most of the time 🤕
🙋♂️ Have you tried both frameworks? If so, which do you prefer? Let me know down in the comments!
Check out my website here: https://www.julianmichaeltechnologies...
Follow my other socials here:
Instagram: / jmichaeltech
TikTok: / jmichaeltechnologies
Facebook: https://www.facebook.com/jmichaeltech...
Twitter: / jmichaeltech
#shorts #iosdevelopment #swift #swiftui #appdevelopment #mobileappdevelopement #coding #programming #iPhone #iOS