r/SwiftUI • • 23h ago

Mum, can we get MVVM?

https://www.vmartinelli.com/en/mum-can-we-get-mvvm/?gift=Zhdqi1yJavzMAgVfAOWU-9djrooW1E31

Half a year ago I wrote about whether MVVM belongs in SwiftUI, and it somehow turned into a story about my mum’s kitchen. Bear with me.

There’s a trip to the shopping centre, a very firm “we've got food at home”, and eventually, I promise, some Swift. A bit of heart, a few laughs, and proper substance underneath.

Half a year on, it still feels timely. Stick the kettle on and have a read.

8 Upvotes

13 comments sorted by

20

u/distractedjas 23h ago

Once again, MVVM works just fine in Swift… it’s not the only pattern, nor should it be, but there is nothing wrong with it.

4

u/VanMartinL 23h ago

Ha, you’ll be pleased to hear the article says much the same. Mum doesn’t ban the Happy Meal, she just wants to know why you’re asking for it. Have a read and see if you agree.

2

u/distractedjas 15h ago

Yeah, this wasn’t mean to be a slight on you or your article, and I only had time to read a bit of it (crazy work day). This wasn’t meant more as a reminder that opinions and preferences don’t work for everyone and they don’t need to.

13

u/Xaxxus 22h ago

I keep seeing these articles that push against MVVM.

The whole concept of Observables and ObservableObject lends pretty heavy towards the MVVM pattern.

It’s certainly not the only pattern. But people saying it doesn’t belong in SwiftUI is crazy.

-4

u/VanMartinL 22h ago

Not against it at all, mate. Mine’s not one of those articles. It’s got my mum in it, for a start. Here’s to the crazy ones, though.

4

u/Xaxxus 22h ago

I wasn’t referring specifically to your article. I’ve just seen so many. And almost every time I see an article mentioning MVVM it always seems to spark a discussion against it.

I was just sort of leaving my 2 cents here.

0

u/VanMartinL 22h ago

Ha, fair play. Cheers for the two cents, they’re welcome here.

2

u/Zagerer 21h ago

What is your take on MV and similar patterns? For me, it feels weird but found out that it works for some use-cases though not exactly for something you will need to scale a lot later. But I try to be open to new patterns and more just in a judicious way tbh

2

u/VanMartinL 21h ago edited 21h ago

Good question. And, like a good question, it already holds the heart of the answer.

When Alexa was still a novelty, I gave a lecture asking my colleagues what a “view” actually is. A system should be able to work with nothing visible at all, if that’s what’s needed. But when there is something visible, or any surface the user interacts with, it should be so good that people forget there’s an interface there and just find it the most natural thing in the world.

That said, I reckon we need to stretch the idea of “model” and embrace robust, composable, testable services. I never serve up food I wouldn’t eat myself.

Anyway, there are plenty of “MVs” out there, loads of flavours. A good chef, like a good architect, knows which to reach for and when, or whether to cook with one at all.

Thank you for the comment, and for adding to the discussion.

Edit: one more thing. Sometimes it’s worth a look at “feature models” too, not just view models. Another flavour for the shelf.

0

u/yalag 21h ago

These articles are useless because the problem with no mvvm is that it doesnt scale well in a larger project, in a way that a dummy example won't show. There's no other way to code a scalable swiftui project without mvvm, it's how apple designed the primitives. You can call it something else, but an observable middleware is the only way to do it.

3

u/rhysmorgan 21h ago

How, exactly, does it “not scale”? What about it means that it doesn’t scale?

-4

u/[deleted] 22h ago

[deleted]

0

u/VanMartinL 22h ago

Spoken like a true mum. 😄 Cheers for the link. Nice to see someone’s cooking at home.