r/iOSProgramming • u/ibuprofane • Dec 17 '22
Application I created my latest production-grade app in SwiftUI. Here's what I learned.
I've seen a lot of posts lately regarding the should-we/shouldn't-we in transitioning to SwiftUI and thought I'd chime in with my recent experience.
Some background: I'm a lifelong coder who hated Obj-C and started writing Swift on Day 1 after ordering my MacBook Pro on Day 0. I've done the corporate gig, but currently work for myself. I started a popular light show app around 8 years ago, which is almost entirely written in Swift/UIKit with Storyboards. Previously I've reused these components when writing new apps.
For my new app, I planned to write the new core user interface entirely in SwiftUI and reuse the view controllers and storyboards I had already created for additional features such as user settings, light pairing, Firebase authentication, and purchasing. The pitch from Apple is that SwiftUI and UIKit are interoperable, so I thought I would give it a try.
The reality is that once I began writing in SwiftUI, the code was so fast and easy to update that it made more sense to write new SwiftUI for most of these components rather than adapt the old, clunky UIKit code. Most SwiftUI views were completed in a day, and since I had done a reasonable job of keeping the control code separate from the user interface, I was able to drop 99% of the UIKit code and only keep one view controller that was essentially a drop-in.
All in all, this was about five months of solo, full-time development. From scratch, this app would have taken much longer to complete, but I was able to adapt many solutions I had already created for previous apps, including Firebase cloud support and subscriptions with promotional offers, as well as my extensive light control library. The next steps are to begin some marketing and advertising efforts, but those won't start until after the new year.
If you'd like to check out the app it's available now on the App Store: https://apps.apple.com/us/app/dramatic-light-presentations/id1637747559 I also have a web site that describes the features in detail: https://www.dramaticlights.com
Q&A: "Do I still need to learn UIKit?" - You will encounter UIKit code in your travels and have to be able to work with it, but you should probably be writing SwiftUI with all new projects now. If you're a corporate coder or have a large code base YMMV but the sooner you transition the happier your life will be. Similarly, when Swift was originally released people said that you'd still need to know Obj-C, which was true but also overstated.
"Is SwiftUI 'ready' for primetime?" - Yes, I'd say the version as of iOS 15 is market and developer-ready. iOS 16 has some nice improvements but you'll be targeting a lot fewer devices (only 15% of market). By choosing a SwiftUI iOS 15 over a UIKit app with a lower target version you'll be sacrificing 5-15% of the market, but since the vast majority of users are on those latest 2 OS versions I think it's an acceptable loss since the other users will probably upgrade at some point and the up-to-date users are more likely to buy apps anyways.
"Who shouldn't be writing SwiftUI?" - If you have a boss or client who is going to demand that the user interface look and act a certain (uncommon) way, SwiftUI might be a hassle. SwiftUI has a way of organizing layouts that's fantastic if you're a developer trying to quickly write and release apps, but many things can be customized to high standards, although perhaps not always in the way you would like. I wanted an all-native solution, but still used a few different third-party controls in cases where the native implementation was missing or lacking (e.g. SwiftUIPager to function as UIPageViewController). If you have a reasonable and flexible boss or client who prefers to save money on development costs over nitpicking UI details, then you should use SwiftUI.
"Where was your biggest time savings?" - Designing with live preview was fun and easy (until it wasn't). Prototyping a large, complex user interface in code is usually difficult because it can require a lot of re-coding after you test it out on a real device. This was much easier with the way SwiftUI is designed because refactoring large UI components isn't as much of an effort; often, just moving a struct from one place to another. Data bindings make it easy to save and manage data, streamlining the process. Where this process fails is when you have a large app with long compile times. Some changes in SwiftUI code can take effect in the Previewer without compiling, but as soon as you touch code or delete a value, it will cause a recompile, which for me takes about 30-60 seconds. That's too long for practical live preview, so at that point, I might as well just preview on-device. For creating new, complex views mid-project, I have a sandbox project where I design, so I can have "Hello World"-level compile times.
11
u/saintmsent Dec 17 '22
Thanks for sharing this. I have a very different experience from trying to use SwiftUI in my corporate project. Answers to all of the Q&A questions should really be more "it depends" than "outright yes"
I don't think that's good advice at all if it's intended for somebody who wants to get a job in a company. Most positions require UIKit knowledge because there's a lot of UIKit code around, as you said. Most projects are either fully UIKit or just started transitioning, and even for mostly SwiftUI ones you will need UIKit skills for a while to fix the shortcomings. Maybe it was intended only for indie people or freelancers, but then there should be a note on that
Unfortunately, most clients want UI to look a certain way (no necessarily uncommon), which is what they are paying for, essentially, and also SwiftUI still can't do some fundamental things. Anything that relies on getting a scroll offset from the list is non-existent, customization to a navigation bar is very limited, navigation isn't very good (unless you can afford iOS 16+), etc.
2
u/ibuprofane Dec 18 '22 edited Dec 18 '22
It was great chatting with everyone. My methods may be foreign to a lot of people but they work well for me because I can get features direct to users quickly and reliably. After working in-flight entertainment for 10 years I decided to quit corporate. I worked every single night and weekend for on my ideas for 18 months until something hit and I was able to afford to leave. My hope is to inspire others to pursue their ideas regardless of the endless chorus of "no/don't/can't/shouldn't".
My users generally appreciate my candor. I own the bugs in my app; I'll fix them promptly and learn from them. I respond to every email. I've implemented zero-day features to users who ask nicely. I have the freedom to call out users who are rude or disrespectful - I don't want their business. I keep a log of every user request and try to grok the most valuable features. Speaking of value: the Valve method of value-driven software development works - read their manual. If you've got writer's block, try "The War of Art" by Steven Pressfield - it helped me understand the difference between an amateur and a professional in this world. Learn to take public criticism, including app reviews - your first few 1-stars will sting a bit (*especially if they're true*), but if you take the feedback in stride you'll continually improve and they'll eventually be rare (and often ridiculous).
Speaking of feedback: If you've gotten this far and have an interest in this kind of app and have the necessary lighting hardware, I'm very appreciative of constructive user feedback and generally reward users with unlock codes. My requirement for this offer is that you email me at kevin@nrthrnlights.com beforehand and let me know how you plan to use the app in a live scenario. Then, I give you access and later you write a one-page-ish email telling me how things went and actionable things I could implement that would improve your use case. I make the same offer for YouTube reviews. (meta: This is how you make great products and build a community.)
3
u/rursache Swift Dec 17 '22
It’s VERY common to have a client/boss asking for the UI to look in a specific way.
Not to mention that your app UI is borderline ugly and very “busy”. Hardly a “beautiful UI” example (honest feedback).
Interesting points tho. Imho SwiftUI still needs 1-2 years to mature until I give it another shot tho.
3
u/Batting1k Dec 17 '22 edited Dec 17 '22
Completely disagree. If you’re a complete newcomer to iOS development, maybe. But if you’re trying to get a job anywhere between now and the next 2-3 years (at least), you will certainly want to know UIKit, and employers will expect it.
As easy as SwiftUI makes some things, it still has a lot of growing to do and you’ll likely need to dip down into UIKit at one point or another.
Lots of companies are only starting to experiment with SwiftUI, mainly when building internal tooling or very, very simple views here and there.
Even then, if you joined a company that was using, say, 50% SwiftUI in their app, you’re still going to have to maintain the other 50% of UIKit code that’s lying around, or at a minimum have the knowledge to correctly migrate its functionality to SwiftUI.
I don’t understand why people come on here and say, “SwiftUI works great for me, so you probably shouldn’t bother with UIKit anymore!”
UIKit has been growing for almost 15 years - to think that SwiftUI is ready to replace it after 3 years is silly.
1
u/zaitsman Dec 18 '22
Yeah, the reason is worked for you is that the app is very simple ux-wise with very common building blocks.
In fact with good knowledge if UIKit you could probably write the same with code-only in comparable amount of time.
What is good in your write up is the acknowledgment of the fact that when the app requires a lot of very distinct concurrent experiences and workflows, swiftui is just unable to deliver.
UIKit will let you stay about as abstract over the UI as swiftUI yet at the same time you can go as low as drawing individual pixels, all with ease and without side effects to other views in your app.
1
u/JiraSuxx2 Dec 17 '22
Thanks for sharing, I’ve avoided it so far.
0
u/[deleted] Dec 17 '22
[deleted] — view deleted comment