macOS Virtual Machines with Bushel, and SwiftData with Leo Dion

Peter Witham:

What's up, folks? We're going to be the other episode of the Compile Soup podcast or videocast if you're watching this on YouTube. I have a regular on the show here. Her name is gonna be familiar with you and a very good friend of mine, Leo Dion. How are you doing, Leo?

Peter Witham:

How's it going, buddy?

Leo Dion:

Good. Good to see you and hear you, Peter. Welcomed. Happy New Year. Happy,

Peter Witham:

to you. To you. Yes. We are here. The year of the headset is what they will put in the record books.

Peter Witham:

Right? Yeah. Maybe. We'll we'll see.

Leo Dion:

We'll see in, what, February 2nd. So yeah.

Peter Witham:

Yeah. It you know, it's as good as here. Right? Yeah. And and maybe we'll talk about that later, how it just appeared out of nowhere.

Peter Witham:

Like, oh, by the way, it's coming out next next month. You know? Yeah. But we, we wanna talk about a project of yours here, an app that you've got out and that I've been playing around with. Very useful app as well for developers, Bushel.

Peter Witham:

And, we're just gonna dive right into this here. So give us an overview of Bushel, what it does, and what it is.

Leo Dion:

Absolutely. So, I've always been interested well, one of the one of the things I was telling the story of is, like, it's cool to develop for the Mac because you don't have to deal with, like having to debug on a different device. You can just debug it on your own machine. But the issue I've run into is I cannot set it up and, like, I can't reset simulator in Mac OS. Like, there is no ability to do that.

Leo Dion:

I can't just throw up a Mac quickly and test an app with a specific configuration without, like, breaking something. Right? So, that's kind of the genesis of the idea behind Bushel was I wanted a iOS simulator from macOS. On top of that, like, I've had a lot of situations where clients had an old version of Xcode. They, like, haven't touched their code based in years and wanted you to fix something and, like, it's just a pain in the neck to do, and I wanted a quick and easy way to do that.

Leo Dion:

And that's kinda where Bushel come came from. I mean, I had done some stuff with, like, VirtualBox and parallel well, mostly VirtualBox, honestly, And it just wasn't a great experience. It works, but it's not really focused for, like, developers in our space. And, that's really what I wanted to do. I wanted to create a good looking developer focused VM app for macOS iOS developers or even people like, I've had issues where I've had a client who needed me to set up a development script so they can get developers up and running and they wanted to, like, install certain apps and, like, I wanted to be able to do that on a Mac and be able to refresh it and try it again without having to, like I want that clean clean install experience, and have it working that way.

Leo Dion:

And, so if you're building a script too, I think this is great.

Peter Witham:

So yeah. Yeah. And it's interesting, because, you know, it's obviously very quickly the immediate comparisons that come up is VMware parallels, all the other ways of doing these things. Yeah. And the problem with a lot of those is that they have to try their best to cater for many different scenarios.

Peter Witham:

Right? Right. Like, you know, I, you know, I've done this, and I know other folks have done this. For example, you install a a win a virtual machine, your host of choice, for Windows so you can play games on your Mac and things like that. And the problem with that is they all enable for that to work, they have to be very generic and and and Right.

Peter Witham:

Meet many different requirements as opposed to something that is squarely dedicated to saying, look. We wanna give you Mac convenience, Mac performance in a VM on a Mac. And and people would be forgiven at first for thinking, well, you know, why would you want a virtual machine of the same machine? But you raise a very good point, which is, we often especially as developers. Right?

Peter Witham:

We have all these fancy tools, all these customizations, all these things running in the background, scripts, customized terminals, all these kind of scenarios that are actually really bad for testing, for example. And the best way to do this, like you say, is a give me a a a straight up, install of of, say, you know, some flavor of macOS that better simulates the real world scenario for most users. And, you know, yes, there are other ways you can do this, but they're all very involved. And, again, it's a whole bunch of files and all sorts of things. What I found that I liked about Bushel is it's a case of, you know, make me a a a Mac, VM of this.

Peter Witham:

Okay. That was it. You know? And it's done. Good to go.

Peter Witham:

And like you say, if you need to do another one and just a reset, it's that quick as well. Right?

Leo Dion:

Right. Right. So, couple of things I wanna touch upon is, like, one thing I was just thinking about is, like, if you have a Linux machine and I don't think this is quite a thing on the Mac, but, like, I've had Linux machines as Linux desktop machines, and, you know, the kids will wanna play a game. And there's, like, a specific tool set up to play Windows games on Linux. And, like, that's kind of what I'm trying to do with Bushel here.

Leo Dion:

Like, yeah. Okay. You can do you can run wine, right, and set wine up and all that crap, but there's no easy way to, like, specifically just play a game on Linux that runs on Windows. And here, like, I have a very specific use case, VM app for developers, who are in the macOS space. And, the thing you bring up about, like, being able to reset and, like so I take advantage of snapshots.

Leo Dion:

Essentially, I use the, snapshot file snapshot feature that's built into, macOS and a f, APFS. And I'm using that so that way you can take snapshots of VM at a specific time and roll back or export or do whatever you want, based on that snapshot. So, I kinda think of it like a safe states, if anybody's familiar with what that means. And that's kind of the idea behind it is just being able to rewind and fast forward and go back and, like, do whatever you need to do to, like, customize your machine and and roll back in case you made any, you know, boo boos on the way.

Peter Witham:

Yeah. I was gonna say that's the other beauty of this too, right, is, you know, if if you do something and it goes horribly wrong or you you mess something up and you're testing a script and something horrible happens is okay. You you know what? You've not ruined your host machine. Just Right.

Peter Witham:

Delete the VM and start over. And, you know, that is so important because I was trying to think, like, you know, the other options. Right? And I know that every year, probably, I'm not the only one that does this. New Mac OS comes out, the new betas and everything else, and, you know, your options are, 1, install it on my main machine.

Peter Witham:

Folks, don't ever do that. It's a bad plan. Or it used to be, in my case, okay, I'm gonna install it on an external drive, and everything comes with that. But even that's not so easy to do now compared to how it used to be so easy to do. And and so something again like virtual machines is like, great.

Peter Witham:

You know? If I presumably, let let's take this year for example. Right? There's gonna be a new version of macOS coming. But but is the betas, you know, like beta 1, beta 2, and so on and so on come back?

Peter Witham:

You can you can take this because of the way your system works, I'm guessing. Correct me if I'm wrong, but because you can download the file. Yep. Yeah. You could It

Leo Dion:

takes that IPSW file. You can just download it right off of the Apple developer page. I mean, you could download the beta for whatever the macOS beta is today and, like, install it in Bushel and try it out. Obviously, there won't be as many changes as, as you might see with Well, we hope not. Right?

Leo Dion:

Right. With what comes down here

Peter Witham:

changes this late. Yeah. Now here's a question for you because I didn't try this. So I'm on you know, as like most folks, I'm guessing at this point, I'm on the Apple architecture. Right?

Peter Witham:

And I, presumably, I cannot install the in like, an Intel version of the OS. Right? Because No.

Leo Dion:

It would take advantage of the hardware. And it only works on Apple Silicon. So if you were to install social on a Intel machine, it wouldn't work. I'm actually talking to Apple about seeing how I can get it removed for Apple machines because the virtualization framework requires, Apple Silicon to run.

Peter Witham:

Okay. Which, you know, let's be honest. It's really, at this point, probably not a problem. I do know some folks that have Intel machines, and I think even they've realized, look, you're gonna have to step up at some point. Right?

Leo Dion:

Right. Right. Right. We're 3 years in here. Yeah.

Peter Witham:

That's it. It's like, you know, you got you got a even Apple has upgraded all of their machines at this point to to the m chips. Right? Yeah. Yeah.

Leo Dion:

And I think, like, a lot of CI machines are moving over to silicon too. So

Peter Witham:

yeah. Totally. Yep. Because it's so fast and, I mean, at this point, why wouldn't you? Right?

Peter Witham:

Right. You know, give it probably what? Another year, and you you probably won't have any options at that point. It's like, nope.

Leo Dion:

I think I think this year or next year may be the first one that doesn't support Intel. I think I think we're getting close to it. Yeah.

Peter Witham:

Yeah. And, you know, the the transition's being good while we're talking about that. Mhmm. Yep. You know, so the the beauty of this app really is spin and, you know, again, this is me speaking from my experience trying it out.

Peter Witham:

Spin it up quickly, use it, power it down, destroy it if you need to. Or in my case, you know, the way I do it is I just keep, like, okay. You know, here's a pristine install. Keep that as a as a like you say, you know, do a snapshot or whatever. So I don't even have to do the install every time.

Peter Witham:

I can literally just say, hey. Make me another one of those. Yeah. And any customizations I may have done to go with that, you know, it's it's it's already set up. The one thing that I find that with all of these, and, I did test this with your one as well, And it's not a you know, unfortunately, I think this is an Apple thing, and and you might be able to shed some light on this.

Peter Witham:

Yeah. Because I've I don't understand, in any kind of virtual machine, you're you cannot log in to the App Store. Yeah. And I'm sure there must be some reason for that. But I

Leo Dion:

log in into any of Apple's systems through a VM. So Apple ID doesn't work, App Store doesn't work, any, like, any stuff with, like, developer like, where you sign in with Apple ID. Like, if you go to Xcode, do you want to download your certificates? No. Can't do that through Xcode.

Leo Dion:

Yeah. It's a it's a challenge, and I've been researching it. It's like my white whale, I guess, of, like, things I could fix, or work around.

Peter Witham:

I mean, does Apple does Apple explain Yeah. Privacy?

Leo Dion:

No. But they think I think it's by design. There was a there was a Quinn answer, ask, you know, Eskimo the Quinn or Quinn the Eskimo, had a question answer regarding that and it sounded to me like it's by design probably because Apple like, people, like, go for it file a feedback feedback on it, but, Apple usually returns it back as as designed. Yeah. So it's kind of my gut feeling.

Leo Dion:

Is there a way around it? I doubt it. But, you know, we'll see. We'll see. I it's like I said, it's my white whale.

Leo Dion:

If I can figure that out, that'd be great, but we'll see.

Peter Witham:

Oh, see, you know, where I was going with this was this is the one thing well, maybe there's others, but I've never got past this one. This is the one thing that prevents me from having, a scenario that I'd like where, you know, I can't do like I used to do with, like I said, the older versions. I would have a completely pristine setup kind of what I would call an external drive with, like, the PETA image. Like, everything's set up exactly how I want it. And if something goes wrong or I wanna start again, I reclone that back to the internal drive, machines up and running.

Peter Witham:

And I would love to be able to do that with virtual machines, but, you know, ironically, because I wanted to embrace the the the macOS App Store, so many apps I use are in there. Therefore, I can't use them in a VM. Do you know what I mean? So Mhmm. It prevents me from having kind of my panic scenario, virtual image at this point.

Peter Witham:

You know?

Leo Dion:

Right. Right. Totally. That totally makes sense. Or just like, you know, we're looking into iOS development, so future future for Bushel so you can run and, like, we're testing that scenario, making sure the USB connections work, and making sure you could just, like, run on your iPhone because who knows if you can even get the certificates you need, like, if you can't sign in, tax out.

Leo Dion:

So, yeah, we're looking into all those situations, right now.

Peter Witham:

Interesting. Because I was gonna ask you about that was, you know, the this with Bushnell on that, do I have when I'm running a virtual machine of of the Mac, putting aside the App Store issues, do you get pass throughs for all of the Apple hardware, or are there some restrictions that it's like, nope. This isn't gonna work for you, or is it really sort of, like, truly having your second Mac

Leo Dion:

sitting in front of Yeah. We're looking into that right now. We've looked at some stuff with clipboard that didn't go anywhere. But the the next thing right now is just USB. And then we're gonna add file sharing soon.

Leo Dion:

So that's gonna be something we're gonna set up. Yeah. It's, like, basically a way to do a central place for sharing files. And then I'm trying to think what else I wanted to do. Man, what what else was the other thing?

Leo Dion:

I mean, we've had work, some requests for, like, custom display resolutions.

Peter Witham:

Yeah. Things to that. That'd be useful. Yeah.

Leo Dion:

Yep. So, yeah, that's definitely something we're looking into as well.

Peter Witham:

Nice. Nice. Yeah. Because as soon as you say that, I'm thinking to myself, you know, when I do, like, tutorial videos and things like that, if I could have, you know, like, run a a Mac VM and, say, have the screen set to, you know, 1024, something like that, and then just capture it at that. I don't have to do any scaling or or any worrying about that.

Peter Witham:

Exactly. Yeah. Perfect for that. Yeah. Yep.

Peter Witham:

And and live streaming too. You know, it's kind of at the moment, it's like, oh, do I do I live stream my whole whole desktop and hope that I'm not exposing something to the world that I didn't want to? Or if I could, again, have a VM with a window of a specific size, you know, tell the CAPTCHA software, go grab that and and be safe. Time for a break. Hey, everybody.

Peter Witham:

It's Peter Whittam here from the Compulsory podcast. I wanna tell you about Setapp. Setapp is a service that provides a subscription fee of just $10 a month and you get access to over 200 Mac applications and it's also available now on iOS as part of that deal. I use the service because it just has a ton of really good first rate apps that I use all the time. And for me, it's invaluable as a developer to have access to tools for things like APIs for planning projects, writing emails, writing documentation, and you get all of these things including database apps, all of that kind of stuff right there on the set up service for just $10 a month.

Peter Witham:

You can use as many or as few applications as you need. If you're interested in checking this out, go to petawithamdot competerwitham.comforward/setappsetapp and you can see the details there. And it's got a link that you can go over and start using the service and see how it works out for you. I strongly recommend this to every Mac user. Break time over.

Peter Witham:

You know, it's it's, Right. You know? And that's that's actually another aspect of this is too that we should talk about. Having having it run-in a virtual machine like this, you know, presumably, you can, by default, if you want, be completely isolated. So whatever happens in inside that virtual machine, you don't have to worry about your host machine.

Peter Witham:

Right?

Leo Dion:

Right. Exactly. I mean, that's a big part of it is just being able to yeah, like, what you can do whatever you want with your VM and not worry about, like, breaking anything on your host machine. Yeah. Nice.

Leo Dion:

Part of it. Yeah.

Peter Witham:

Yeah. Especially useful for for, like, research, you know, like, whatever it may be or, you know, or, you know, these folks who have to sit and look at infected machines, and it's like, look. You can look at it in a VM and not worry about, you know, getting One

Leo Dion:

of the things So, like, one of the things that's both a use case and, a future feature is developing, like, a guest tools app. So that way you can control all sorts of things in your VM from Bushell, like SSH or file sharing or anything like that. Nice. And that's a great example of what an app I wanna build in the VM for the VM because, I don't wanna, like, mess stuff up on my host machine if I, like, accidentally do some admin thing. And that's, definitely what I'm trying to do with, with the guest tools.

Leo Dion:

That's kinda the next one of the x big things we're looking at looking looking at doing because, yeah, I think that opens up a lot more features, for for users to be able to do stuff.

Peter Witham:

That's it becomes very meta at that point, doesn't it? Using the for a company. The tools to develop the tools. Right?

Leo Dion:

Yes. Exactly. Exactly.

Peter Witham:

Yeah. Yeah. Like that. Nice. Nice.

Peter Witham:

So, you know, we'll link folks, we'll put lots of links in the show notes for this, but, tell folks where they can go grab this.

Leo Dion:

You can go to get Bushel dot app. It's, get Bushel dot app is, the URL. And then from there, that'll take you to the App Store and all sorts of fun stuff about Bushel, the making of it, and different release notes and all that stuff.

Peter Witham:

As far as, like, a pricing structure on this, how does that work for for those who are curious?

Leo Dion:

Yeah. So it has, it's free to use for most most of the features, and then there is a in app purchase that's available, for a membership. So you can if you get the pro version, right now it's priced at $11, monthly or 65.99 for the annual membership. Obviously, we'll be adding more features throughout the year, but

Peter Witham:

Sure.

Leo Dion:

Right now, metadata, so be able to give a name or, like, give a description on a snapshot. And then automatic snapshots is the other feature where as you're using the app, as you're using the VM, it automatically takes, takes snapshots every however often you wanna take it, which I think is a big, big deal. Oh, yeah. And, like, we'll be it's all uses a specific API so these you can always delete these snapshots later pretty easily if they're taking up too much space. But, yeah, those are the 2 big, premium features that we have, and then we'll be adding more throughout the rest of the year.

Peter Witham:

Nice. Is it possible and I didn't look this one up, but it strikes me as something now. Can I back up those snapshots to, like, an external drive or or something like that?

Leo Dion:

You can, you can export a snapshot into a new VM. Nice. Nice. But the VM the way the snapshots work is it uses special stuff in APFS, so I don't have access to, like, the actual file data. Mhmm.

Peter Witham:

I'm

Leo Dion:

gonna be able to export that per se, but you can export, a snapshot into a VM and then use that kinda like a branch, right, or a fork Yeah.

Peter Witham:

That's what I'm thinking. Yeah. Yep. Yeah. Okay.

Peter Witham:

Cool. Alright. Awesome. So talk about building an app like this because I would imagine it's a very different approach in some ways to just your everyday app. Right?

Peter Witham:

Because you're talking about an app to essentially manage an OS at this point, which is very different than, you know, your average app Yeah. That just runs. Right? Talk to talk to us about that. What fun did you have?

Leo Dion:

Well, let's let's talk about virtualization. Like

Peter Witham:

Mhmm.

Leo Dion:

So they've had this hypervisor framework out for quite some time on Mac OS, it looks like, but it's all c level and honestly it's kind of intimidating and probably isn't maintained very much. And then a couple of years ago, I'll say 2 years yeah. 2 years because it was a year Monterey came out, they released a virtualization framework, which is all swift based with objective c behind the scenes, which is, you know, better than c based, right? And, I started to dabbling into that and it was, like, actually really easy to get going once you figure out some of the stuff that's going on behind the scenes. Honestly, that's like not the hardest part.

Leo Dion:

There's a few tricky things with concurrency. They want everything to run on the main thread with that stuff but otherwise

Peter Witham:

as

Leo Dion:

long as you say it's main actor it works right so yeah that's fine it's honestly like the SwiftUI stuff one of the things I talked about in the article was that I had already started developing this like after WWC last year, and I was, like, trying to support Monterey, and it was it was a challenge. And I, I didn't lose interest. I just had more work than I can handle and, like, bushel went by the wayside. And then when they came out with Swift Data, I was like, okay. This is like this is the thing that's gonna make it a lot easier for me to, build this app and use it.

Leo Dion:

And because I was Peter, I have this, like, thing using combine and user defaults to store my data. It was, like, it was awful. Interesting. Yeah. Because, like, I was looking I didn't wanna do core data because I knew core data wasn't gonna be long for the world.

Leo Dion:

And I wanted to store your VMs, your images, and all that stuff. And so I I had this hacked thing together for my data and then once with data I was like, okay, good. I could throw all that crap out the window and start from scratch. And so, yeah, it uses a lot of swift data to manage machines and access to machines and stuff and it's all sandboxed so that's another challenge there. And just figuring out how to work with the sandboxing system.

Leo Dion:

Yeah. I could go on and on. They added a new snapshot feature this year, which was useless because you had to use a, what are we on right now? Sonoma. You had to use a Sonoma VM and, like, nobody's gonna wanna use a Sonoma VM because part of the reason you're using this app is to be able to use an old OS.

Leo Dion:

So I don't even use the new new API. I just end up using file snapshots, but yeah. It's it was interesting. I learned a lot of stuff and, you know, working with SwiftUI all through that that maze, was interesting.

Peter Witham:

Well, I bet now, you know, the the part that caught me there that stands out more than anything is using user defaults because maybe and and maybe I'm wrong or maybe this is part of the problems that you hit was I always tend to think of user defaults as storing this you know, like, you got a little bit of data to store. You you use, you know, simple data, go with user defaults. But I would imagine you've got a pretty fair amount for something like this.

Leo Dion:

Oh, Peter. I was doing, like, codable data structs and storing them in user data. It was awful. Or user defaults. It was awful.

Leo Dion:

It was just like, yeah, this is I just I was so against using core data. I went with this route. Honestly, I should've just went with core data, but now that's with that is how, like, that's what I'm going with, and that's that's worked really well to store all this information. It's not a lot by any means. It's pretty simple, honestly, but, it's just perfect

Peter Witham:

for you to manage it though.

Leo Dion:

Right. It's a and it's perfect for relational stuff, so that really helps a lot.

Peter Witham:

Wow. Yeah. You know, that that that's a lot right there. I feel like there could be a whole series of, like, you know, my pain with user defaults and and doing this. Right?

Peter Witham:

Yeah. It's bad. Yeah.

Leo Dion:

The code's bad.

Peter Witham:

So I can imagine when when they first announced you know, Swift Daddy, you

Leo Dion:

were like, oh, thank goodness. Right. Because I knew we all knew something was gonna come out. Right? Yeah.

Leo Dion:

Even more so than, like, SwiftUI. I feel like we've been waiting for core data alternative. Core data is not bad by any means, but it definitely has a lot of objective c craft to it. And with Swift data, it's not I wouldn't, like, if you're already using core data, stick with core data. But, I think next year, if you're starting a new app, I would totally go with swift data because I think there's a lot of weird concurrency things that are going on with Swift data right now that they still have to work out.

Peter Witham:

Alright. Here it is. The one thing that I cannot do without every day and that is my coffee. Anyone that knows me or anyone that's listened to any of my podcasts or anything else knows that I absolutely cannot operate without my coffee and I love good coffee. So here's the deal.

Peter Witham:

I'm gonna give you one free bag of coffee by going to peterwydham.comforward/coffee. There is a wonderful company out there that follows the fair trade practices, helps out a lot of independent roasters of all sizes, and the operation is simple. What you do is you're gonna go to to peterwhidham.com forward slash coffee. You sign up there. You get a free bag of coffee sent to you.

Peter Witham:

Yes. In return, they say thank you to me by giving me some coffee, but that's not the reason I'm doing this. The reason I'm doing this is because I have found so many good coffees that I just would never have come across, heard about or experienced without this service. Trade coffee is is just fantastic. You know, there are plenty of places out there.

Peter Witham:

We all know them that supply coffee, good coffee. You can go to the store, get the coffee, but there is nothing better than discovering new independent roasters and supporting them, discovering new flavors of coffee, new grinds for you can set it up. It's very smart. You tell it the kind of coffee you like, and over time it gets better and better as it trains in on your selections and your choices and gives you exactly the coffee you're looking for and recommending new ones that that will be very similar. Every time I get a new packet of coffee, I go through and afterwards, I try the coffee.

Peter Witham:

I go through the service and I say, look, I loved this coffee. I thought this coffee was okay or I say, look, I've this was really not for me. And every time I do that, it makes the service a little more accurate on the next selection for me. So again, just go to peterwoodham.comforward/coffee. Get your free bag of coffee today.

Peter Witham:

If you're a coffee lover, you're gonna really appreciate this service. I have been using it for years at this point and thoroughly recommend it. Well, if you're if you're ready for it, I'd like to move on and talk about Swift Data because

Leo Dion:

Yeah. Let's do it.

Peter Witham:

You are one of, you know, one of a small group of people I know that have been working with it, and I know I have some folks working on some courses. And you and I were talking before the recording, and as folks who have been following my other episodes recently know, I I took my first steps into swift data over the holidays. I just felt the press you know, it's one of those it was holiday time. The pressure was off. I could make something that's a complete disaster and not worry about it.

Peter Witham:

And I thought this is the perfect time to sweep data.

Leo Dion:

So can I can I tell you? You wanna know what's even more fun than learning swift data? Learning swift data as it changes.

Peter Witham:

Try that out. Oh, I I bet.

Leo Dion:

I bet. That was one of my biggest challenges was, like, I went into Swift data as soon as the first beta came out, and, oh, it works. And then you try beta 2. Oh, it crashes. Okay.

Leo Dion:

Fix it. Beta 3. Oh, it crashes. Oh, it fixes. I don't know.

Leo Dion:

Oh my gosh. Yeah. That would've that was a that was a that was a blast. That was a blast.

Peter Witham:

Was this, like, swift 123 all over again? Is that what you went through? Yeah.

Leo Dion:

Yeah. Yeah. And they would they definitely they changed some attributes. Obviously, this is also their guinea pig for macros. Right?

Leo Dion:

Because everything's a macro here. Yep. So attributes would change. Well, we'll get into the biggest thing that kept changing and it's still an issue with it. But, for me, like and this we've I've done I did this episode, this really great episode, 2 episodes with Stuart Lynch.

Leo Dion:

And we're talking about, like, learning new stuff. And, like, one of the things is, like, you come into any new API. I've done this so many times now where you have this, like, preconception of how it's supposed to work based on how you've done stuff in the past. And like for me, like, I think for some people it would have been, oh, this is how I use Postgres, or this is how I use my sequel or whatever, or core core, Swift Lite. Right?

Leo Dion:

Yep. And and for me, I've actually done database stuff in Swift. My case it's all been vapor and fluent, and like doing stuff that way and they have a really good system for, like, migration and models and queries and all that stuff. It's awesome. And so I already know this really good API for talking to databases.

Leo Dion:

And then you have, like, Swift data, which is Apple's way of doing it and then doing it with this new thing called macros and it's like

Peter Witham:

Yeah.

Leo Dion:

Okay. Well, you gotta do this, you do this, you have to do this, like parents always are optional, but I don't want a parent to be optional. I want a parent to have to be there, but no no no Apple says it has oh, sorry. Okay. Whatever.

Leo Dion:

Just get it to work. And this is how you define relationships. This is it's, yeah. It's like you have to you just have to relearn it the way, the way Apple does it. And for me Yeah.

Leo Dion:

The biggest challenge honestly, comes out of con concurrency. The way concurrency is set up in Swift data is, it's it's it's different, and it's just not the way it's it doesn't do a lot of hand holding and at the same time I feel like it's a little bit guiding you towards the wrong direction. I'm just thankful we're not with at swift 6 yet. Hopefully not this year because swift 6 is gonna be huge and it's gonna, like, throw a lot of curveballs when it comes to concurrency because, like, swift data is just it's it's not ready for concurrency right now. I'll be honest.

Leo Dion:

All the swift data code is wrapped in main actor because I was just sick and tired of dealing with all these issues. That's clearly what I'm doing there right now is, like, trying to unwrap, unwrap all the, main actor swift data stuff because I want a I want a better, you know, user experience.

Peter Witham:

And and that's interesting. Yeah. Yeah. That that was one of the first things that struck me too was, you know, I was like, oh, really? We're gonna do all of this on main actor?

Peter Witham:

And I thought, well, I I hope that goes smoothly. You know? Yeah. And and then to be fair, I didn't do anything massive. So, I'll dive into sort of how I got into it here.

Peter Witham:

I I didn't wanna do anything too complicated and, you know, again, I wanted to do something that I could almost just sort of say, well, that's interesting and walk away from it. You know? Mhmm. Thinking to myself, maybe this year we'll get a whole bunch of swift data stuff at dub dub d c. And then, of course, I remembered, no, we'll probably get a whole bunch of headset stuff.

Peter Witham:

But, I I noticed that, you know, Paul Hudson, Hacken was great to have done a live stream. And I thought, well, hey. You know, I'm I'm gonna sit and watch some of that. So that's what I did just to Okay. You know, it's like, get a grasp of the basics and to see if I could relate it to what I know about core data.

Peter Witham:

Yeah. The good thing is I didn't really have to do that, so that's the good news. But but the it did become very apparent very quickly. Yes. It was like, ah, now I see why we were in a hurry to get the macros out the door.

Peter Witham:

You know? Right. With everything being macros. But then I realized too, actually, I get it. This is this is saving me an awful lot of work and an awful lot of code if I just trust in the the the the macros and swift data was Yeah.

Peter Witham:

Doing what it should.

Leo Dion:

And at least with Xcode, you could see what's going on underneath. It's not all

Peter Witham:

That was the beauty of it was when, you know, I I realized, like, oh, you know what? If I'm not sure, I can actually kind of go in there and look, you know, and not only learn from it but understand. And interestingly, that was that that helped me solve a problem because, I I I spoke about this on a previous episode. My idea was a basic sort of simple one to many kind of relationship. Right?

Peter Witham:

You know, very Mhmm. Like, stop there. And I thought I was being clever. And and, firstly, let's talk about the models. Right?

Peter Witham:

How how you, you know, simplicity of building the model was fantastic. But I didn't read the documentation as far as don't do this. And I set up what I thought was an easy answer for something which was an enom, and that was a bad plan. It was a bad plan in that I didn't know at the time that Swift data and enams are not friends at this time, but also the errors that it was giving me in Xcode that turned out to be the enum that was the issue. Well, the error didn't say anything about that.

Leo Dion:

The the error

Peter Witham:

was completely different. And I this was on a livestream. I spent about 30, 40 minutes with some very knowledgeable folks in the chat room. None of us, like, what does this mean? You know?

Leo Dion:

So what did you end up doing, if you might So

Peter Witham:

because I

Leo Dion:

I I have a workaround for

Peter Witham:

that. Well, my workaround, I I guess it's it works, but it's one of those where, you know, you say to yourself, this just doesn't feel right.

Leo Dion:

Right.

Peter Witham:

So what I did was instead of having an enum, I just created another very simple model with 2 properties, just an ID and, the stream that are basically I needed. The enam itself, what it was was a payment type. So you you had a drop down in the UI, and there'd be, like, Apple card, credit card, so on and so on. Right? Perfect use case, I thought, for an e num until I realized it wasn't.

Peter Witham:

So I just made a simple model with that and then piped in the data. So instead of having the, I basically ended up with a very simple list. But the beauty of what impressed me with Swift data was, you know, it happily mapped that back to the other model, which was, like, the actual record. Right? Oh, okay.

Peter Witham:

Cool. So you had a record that was, like, you know, pick 1, Apple Card. Right? But then you may have 5 records that related back to the Apple card, and I could just list them by saying, show me everything with that card. Makes sense?

Leo Dion:

Okay.

Peter Witham:

Mhmm. Yeah. But I I thought I'd I'd you know, this was one of those, like, okay. Now I'm about to prove why you can't use this, and I'll break it. So I deleted the record that had Apple Card, and and dang it.

Peter Witham:

If Swift data didn't do the right thing and just set them all those records back to, like, the first default of select a card. So yeah. I was like, damn. That's impressive.

Leo Dion:

Yeah. Yeah. So the the thing I end up doing in those cases is, just storing the raw value of the enom in the database. And then

Peter Witham:

Oh, I tried that, and it didn't work for me.

Leo Dion:

Because so I make I make the raw value the actual strong so string. Right? That's stored in the database, and then I create a computed property, basically off of that with the real enum. Now I think about it. Because then you could create a transient you could create a transient property too where it's not stored in the database.

Peter Witham:

Yeah. I think I was using the raw value to display. I don't think I was

Leo Dion:

using the raw value. UI stuff too.

Peter Witham:

I was doing Swifty. Thanks. Yeah. Yeah. Yeah.

Peter Witham:

And that, you know, like you said, that was one of those, like, be prepared to forget what you know. You know?

Leo Dion:

Right. Right.

Peter Witham:

I was thinking, like, old call data ways. You know what I mean?

Leo Dion:

Yep.

Peter Witham:

Yep. And and as soon as I just let all that go and and, again, trusted in the macros, I was very pleasantly surprised at how many things it was it just took care of it, and it was fine. Every time I expected to crash it, it didn't. You know.

Leo Dion:

One thing I wanna talk about is, there's barely any combine in the SARP. I'm a big fan of combine, and I Yeah.

Peter Witham:

Talk about that. Yeah. Because I know you are a big fan.

Leo Dion:

Yeah. Yeah. I've built built it with very little. There is some combined from my old code I did 2 years ago. It's like the downloading part, but pretty much everything else is all observation based.

Leo Dion:

So a lot of did set. It's kinda how I did it. I don't know if that's alright.

Peter Witham:

I think you mentioned that. Do you feel that that's better going forward or would you rather

Leo Dion:

I'm maintaining old apps that use combine and what I'm running into is it's really hard to trace what's going on. Talk to me in a year to see how observations are any better than that. But that's, like, kind of the issue I've run into with combine. Interesting. So we'll see.

Leo Dion:

Interesting. Yeah. Okay. I wanted to mention that because what what I ended up doing a lot is, like, so I use a lot of window groups where you pass in a binding and I'd have to listen to the binding to see if it changes and then let the observed object know on the view. I actually write an article something.

Leo Dion:

Yeah. Yeah. I'm writing an article about that. Yeah. So, like, basically, like, binding can chain like, if you open the app and I say open this VM, then I close the app, and then it'll open the it'll try to open the window, but it won't pass anything to it for at first, and then it will pass the information about the VM.

Leo Dion:

And so now we've got to, like, update the view and the view is reading the observed object. So I ended up setting up this, like, on change. I use on change to, like, listen to changes to the binding and then let the observed object know. The reason I wanna point that out was, like, I do the same thing with queries. So, like, you have a query and you have an observed object, and then it'll listen to changes in the query and let the observed object know so that it can, like, like, let's say Got it.

Leo Dion:

Snapshots. Right? I need a specific I need to take the data from the database and turn it into something that's actually viewable in SwiftUI, then I could do that with the on change. That's a pattern I use a lot, and that seems to be working pretty well, so I'm pretty happy with that.

Peter Witham:

And I would imagine that's, you know, that that's pretty responsive and pretty quick too. Right?

Leo Dion:

Right. Right. Exactly.

Peter Witham:

And and like you say, better chance of it being internally up to date for one of a better way of putting it.

Leo Dion:

Right. Right.

Peter Witham:

And and keeping up with yourself as opposed to, yeah, it could be. Yeah. You could be you you might think you've got one state, but you're a fraction of a millisecond too early, and you've got the other one or something like

Leo Dion:

that. Right. Right.

Peter Witham:

Interesting. Yeah. Alright. Yeah. We'll check back and and, I'll just message you one day, and I'll just be, like, combine.

Peter Witham:

Yes? No?

Leo Dion:

I know. I know. There's gonna be a talk next year on it. There's gonna be a whole group of talks about it. Vision Pro is totally built on combine.

Leo Dion:

Like, what?

Peter Witham:

Yeah. Yeah. That's it. Yeah. Combine is is is come back, and you're you're good to go again.

Peter Witham:

Then you can rewrite it again. Right?

Leo Dion:

That's right. Yeah.

Peter Witham:

That's right. Yeah. Nice. Cool. Well, I'm conscious of the time here.

Peter Witham:

Is there anything we haven't covered here in this episode we wanna talk about?

Leo Dion:

I don't think so. I think we covered it. I mean, yeah, people download the app. It's free. Bug fixes are coming out like crazy.

Leo Dion:

If you have any suggestions, we have a Slack for it too. Great. So if you wanna invite, DM me. I'm on Twitter at leogeton and mastodonleogeton@c.im. So hit me up and let me know.

Leo Dion:

Yeah. I'd love to hear more feedback.

Peter Witham:

Great. And we'll put links for it all in the show notes. Yeah. Folks, absolutely give it a try. You know, it's it's another one of those where it's you know, I look at these things and and the folks that I have come on the podcast, and these are you know, it's a it's a podcast for developers, and it's mostly about development tools.

Peter Witham:

Right? And so, you know, it's it is very much a case of why wouldn't you download it and try it? At the very least, give it a go. Right? But I think, like so many times, once you actually try tools like this, suddenly you realize all those use cases for yourself.

Peter Witham:

Right? You know, it's like when I was talking with, Adam Wolf and we were talking about Muse and Developer Duck and how it has radically changed the way that I do some things for the better because I never had a tool that did it the way it does it for me to realize that this is so much better for me. And I think that this is another one of those tools in the you know, if nothing else, being able to spin up an entire operating system for whatever reason you need it and it goes wrong and just delete it without take your machine going down and carrying on. I mean, you know, that in itself is priceless. Alright.

Peter Witham:

Well, fantastic. Well, Leo, my friend,

Leo Dion:

yes. As you probably plug, I have a podcast of my own. Oh, yeah. Sure. And, you can check out check out my company, Bright Digit.

Leo Dion:

I have all the links to the YouTube channel and the podcast. We have our next interview with, Martin Lasik, who has a YouTube channel. Hey. You say hi

Peter Witham:

to me.

Leo Dion:

Development. Yeah. We'll do. We're talking about Yeah. Game development and pub building in public and all that fun stuff.

Leo Dion:

So

Peter Witham:

Yeah. I I, I hang out on his live streams. Yeah. Oh, you are? Cool.

Peter Witham:

Yeah. No. I I hang out on his live streams. He's he's a lot of fun and and a smart guy and, yeah, say hi for me. He does a lot of great stuff.

Peter Witham:

Awesome. Yeah.

Leo Dion:

Yeah. Yeah. He was gonna be awesome. So yep.

Peter Witham:

Yeah. Cool. Yeah. And and, folks, absolutely, check out the Empower Apps archives. So thank you, my friend.

Leo Dion:

Thank you.

Peter Witham:

Folks, we will leave it there. There's gonna be a whole bunch of links in the show notes for you. As far as myself and this podcast, you know what to do. Compile Swift everywhere. Say nice things about it.

Peter Witham:

I would greatly appreciate that. With that, folks, we will catch up in the next episode.

Creators and Guests

Leo G Dion
Guest
Leo G Dion
CEO and Founder @brightdigit, Swift developer of apps for Apple products. Host of https://t.co/4IruOliR7A. Creator of https://t.co/HfkUdttc2rMastodon: https://t.co/X67t0QqbXU
macOS Virtual Machines with Bushel, and SwiftData with Leo Dion
Broadcast by