r/iOSProgramming • • Mar 10 '22

Article iOS development best practices in 2022

Hi guys, we published an article with 1 min guide to iOS development best practices.

Please have a look and provide us with your valuable suggestions and feedback. The list is a starting for you to get inspired by and should not be used as it is for all apps. Usage differs depending on app size, type, complexity and other requirements.

https://blog.canopas.com/1-min-guide-to-ios-development-best-practices-in-2022-e3f1d009cfa1

If you think we missed something, let us know. We will update it to make it more meaningful for other iOS devs out there.

2 Upvotes

17 comments sorted by

28

u/Own_University6674 Mar 10 '22

In all honestly this looks like a blogspam list to draw traffic to your services, that's fine(ish..). But without context and explanations it simply seems like a list of things YOU happen to be using at your agency.

---

How can SwiftUI be a best practice when it is so controversial for maturity.

Why is Combine best practice over RxSwift? Purely because it is from Apple?

Alamofire seems hardly a requirement anymore, like it was considered before.

Swinject seems like it is something for large complex apps, it wouldn't be good practice for something tiny. Context.

MVVM, Modular, same. Depends on the project scope.

EarlGrey, why not just use plain old XCUITests? They work perfectly fine and I really don't see why we need to use it. At my last company we had hundreds of tests.

2

u/b4sht4 Mar 10 '22

This 👆🏽 👏🏽

0

u/dg02512021 Mar 11 '22

The list should be used as an inspiration and of course everybody has different opinions and that's why we have multiple tools for each use case.
Also, the list is supposed to be the best according to my knowledge and opinion. However, as I had mentioned earlier, it's open for debate and we should all add valuable feedback/suggestions to make it even better.

It would be more helpful to the community if you were contributing instead of complaining!

To add feedback to some of your points-

SwiftUI
Even though it's not mature enough right now, it's going to take over UIKit for sure because it has so many advantages over traditional views. The world is moving toward a declarative approach for UI almost on all major platforms and that's why Apple is forced to come with SwiftUI. It might not be perfect right now but over time major issues will be fixed and SwiftUI will be the default choice for iOS development. I would recommend using it for new projects unless you have a very good reason not to use it.

Use of combine over RxSwift
RxSwift is a great framework and I have personally used in many projects for years. One more advantage RX have over others is that the same framework is available on almost all major platforms like android, JS etc. and thus you would not have to learn new framework if you are already familiar with it.

However, I would still recommend Combine for new projects as it's provided by Apple and that means one less external dependency. It also meets most of the use cases of Rx by providing common operators.

Alamofire
I prefer it over URLSession as it's very easy to integrate it with Rx and Combine. You can use common syntax to deal with Web APIs. Also, we can use Alamofire as a router easily to centralize the application's communication to web APIs.

Swinject
Dependency injection is considered a good practice almost on all platforms. However, I have seen iOS developers using it very little because it's not considered a good practice. Not sure how you would be able to write effective unit tests for your classes if you are not using the dependency inversion principle. Of course, it does not make sense to use it for a tiny little hobby project but if there's any project that we need for the long term and is supposed to be in production, we need dependency injection.

MVVM architecture
I suggested MVVM architecture as it plays nice with SwiftUI as screen/view state is managed in a different object. That's good because, with SwiftUI, View struct can be created multiple times and the state would be lost if you are not using it's annotation to preserve the state. Also, separating business logic and state in view model will allow us to write effective unit tests.

It's very easy to call someone's work spam without realizing the efforts they have put into it. The reason I did not add explanation for each point is because it was supposed to be a 1 min guide, I would not have explained all the benefits in that time.

3

u/Own_University6674 Mar 11 '22

It would be more helpful to the community if you were contributing instead of complaining!

If I were here to complain I would have done that and left. Instead, I gave feedback to you about how your post came across. I also asked specific questions to try to get some reasoning behind the post, which we got.

The issue is that the post is labelled best practices, which generally is a pretty well understood term, while this is pretty clearly an opinionated list. The list itself is fine, you just have to add the context.

5

u/this-is-not Mar 10 '22

Async await might be preferred over using Combine, no?

5

u/dg02512021 Mar 10 '22

Well, it actually depends on the use cases. In my opinion, For one time results, async-await is preferred and for the stream, combine is the best solution.

3

u/is_that_a_thing_now Mar 10 '22 edited Mar 10 '22

Thanks. This is a nice list to get inspired by. One point puzzled me a bit though. Feature flags. I can easily see a FeatureFlag hell as well. At best this is a thing to consider and not a best practice.

It depends on the kinds of features and how teams are organized. The separate developers/teams should always stay coordinated and maintain a degree of consistency with the main/development branch, but they can diverge from the main branch in wildly different ways. Supporting this with flags in the one and same code base can result in a combinatorial explosion of complexity.

A feature that undergoes many changes or perhaps even ends up being canceled would have bothered everyone else for no reason at all.

It will in general be far better to keep things separate until the separate projects/features reach a point of maturity where you can begin to consider merging - with the main/dev branch. (Perhaps then with feature flags for a very limited time)

No biggie though. The list is super useful.

3

u/dg02512021 Mar 10 '22

You are right. It's not a best practice. Also, it's useful in special cases only.

I will update the article in a day or two. Thanks for sharing your knowledge and experience.

11

u/Niightstalker Mar 10 '22

I don’t really see a reason to use Alsmofire anymore for networking requests. The built in URLSession improved by a lot over the last years and is pretty easy to use by itself now.

4

u/anymbryne Objective-C / Swift Mar 10 '22

Heyy, so uhm, just wanna ask. By recommending Sqlite, would you choose it over CoreData?

3

u/foodandbeverageguy Mar 10 '22

Best practices != use all third party frameworks. Other than linting, almost all these problems can be solved natively. If a developer told me Kingfisher was the best practice for downloading images I wouldn’t hire them.

4

u/Budget_Nerd Mar 10 '22

Saved!

Thanks :)

2

u/anymbryne Objective-C / Swift Mar 10 '22

I’m gonna save this and hope for the best

2

u/jjhageman Mar 10 '22

I don’t think it’s fair to label this list as iOS Development Best Practices as it’s far too opinionated and customized to your app and team. For many of these suggestions, you are adding too large of a layer on open source frameworks, and therefore dependencies that each library will be updated and bug-fixed in the future. Imo, most teams/companies should strive to own their own destiny and write their own networking layer, async image loader, keychain wrapper, etc.

For many apps Core Data will be a better data store. Especially those with an object graph paradigm.

Regarding MVVM, since your list is very SwiftUI-forward (which is great) I’m surprised that the Composable Architecture pattern was not mentioned. (https://github.com/pointfreeco/swift-composable-architecture)

The best practices that apply generally across iOS development from your list are: using a code linter, dependent injection (and composition over inheritance), feature flags, modularization (in later stages as the app grows), unit tests, measuring code coverage, investing in CI/CD, and security.

I read this list more as you sharing your team’s tech stack, which I found interesting to learn about from that angle.

-6

u/tbihitesh Mar 10 '22

Hi, I have read your article written by Amisha I about "1 min guide to iOS development best practices in 2022". And I found it interested. You can also check what I have written about the Functional Tools used for iPhone App Development.

16

u/[deleted] Mar 10 '22

[removed] — view removed comment

6

u/dg02512021 Mar 10 '22

Really good point! While the library was good, it has not been updated lately, I will remove it. If you have a better alternative, please suggest it!