Two of our favorite WWDC25 API's

Geoff:

Yes. You do. You did a whole stream about it, and everybody thought it was cool, and you built an app.

Peter:

What's up, folks? Welcome to the CompileSwift podcast. In this episode, we are gonna be talking about some code things. In particular, we have picked some some of the APIs, I guess you would say, of interest from dub dub d c twenty five this year. I'm gonna kick things off here with my first one.

Peter:

But first of all, Gfoff, how are doing, buddy?

Geoff:

I'm doing just great, Peter. Things have been going well pretty recently. How about you?

Peter:

Yeah. Pretty good. The the bonus effect here is not only did I have to do my homework for this, but I got to add a feature to my Job Finder tracker app that actually needed this API. So I got a two for one deal out of this. So I'm really happy this week.

Geoff:

Yeah. Perfect. Let's hop into it. What'd you what'd you discover?

Peter:

So one of the ones that I wanted to look at this year that got my attention way back in dub dub d c '25 was the attributed string and how we can now use that in an editor in SwiftUI. So what am I talking about here? Well, for a few versions now, I think it was iOS 15, where you can display, you know, text. If you're SwiftUI, you'll be familiar with this. Right?

Peter:

Put on text. Put put a string in it, and it will happily show you attributed text. Think of things like rich text. Right? However, jump through a few hoops to be able to edit it.

Peter:

And in my case, I was using a third party library to enable me to do this and then, you know, use the attributed string from there. Whereas this year, we now have it built into the text editor in SwiftUI. So this is something that I went into in great detail, and I'm going to talk about it here. And I'm really impressed. All right?

Peter:

So basically, what happens is, if you are not familiar with attributed text, the way it works is this. Okay? Think of your normal text string. Alright? And then if you make it the color red or you pick a particular word and make it bold, those are attributes or attributes, depending on how you pronounce it.

Peter:

Now, it renders just fine, like we say, when you are looking at this on the screen. But to edit this and store it as a string got a little interesting. So this year they made it simple. And the way it works is this: So, you've got your SwiftUI text editor. You've got two parameters that you can put in there, right?

Peter:

One of which, of course, is your text string, as usual. And the other one that we have is a selection. And we'll dive into these. Now, the best part about this is if you don't want to do anything fancy, Apple has made this very easy for you. If you have some text, regardless of whether it's plain text or whatever, in this text editor already, they you can just select the piece that you want.

Peter:

You're gonna get the very familiar pop up bar with lots of options on there. Now you get all the things you can imagine. Right? Stand what I call sort of standard text editing. You could do bold.

Peter:

You know, you can strike through, italic. You can change the colors, the fonts, and the font size. You don't have to do anything. You get that out of the box.

Geoff:

Awesome. So it sounds like like with a lot of SwiftUI stuff, you're kinda just getting a lot of it for free. You're providing, it sounds like, some kind of binding to an attributed string, probably an attributed string state somewhere. You're putting that in a text editor and then you get a lot of the UI for free that you're getting that little menu with the bold, italics, all the common stuff, right?

Peter:

Yep. That that is all built in, ready for you to use. You don't have to do anything.

Geoff:

Awesome. So it sounds like oh, go ahead.

Peter:

No. No. Go

Geoff:

on. I was gonna say, so it sounds like you get kind of a lot of the basic standard system behavior for free. I know you mentioned the selection argument as well. I'm assuming that that's kind of getting more into the advanced stuff, where if you want to provide some of this functionality yourself?

Peter:

Yes. And the way this works I'll I'll dive into that now, because the the beauty is with this interface. Right? And and once users get used to iOS 26, and I should stress this only works with iOS 26 and up. So

Geoff:

Of course.

Peter:

If you're if you're gonna use it, right, that's your problem right there. But, let's talk about this part here, so this this selection. So in my case, I have, you know, a variable, a state variable, right, selected text of type attributed text selection. That's important. What this does is it tells the editor, okay.

Peter:

This is a state theme. Right? So anytime a user is doing something, they're selecting the text or interacting with it, you know, double tapping it to select it. All that kind of fun stuff. It tracks that for you.

Peter:

So you don't have to go find, like, you know, the range from, you know, a to b or whatever. It's just gonna say the text you've selected. Where this gets interesting is if you want to offer, say, your own custom toolbar. And I'm gonna give you an example of this, a really simple one. Right?

Peter:

But this is a really nice, obviously laid out API to use. So let's say that you add a button, right? And I'm not going to go into detail here too much. If you know how to do a button, you know you've got a label and an action. Okay?

Peter:

So we're just gonna go with making something bold. Let's just do that. Okay?

Geoff:

Yeah. No. If you've seen the list of attributes that you can change on an attributed string, it's ridiculous. They've got like four or five different blocks of them. You've got the Swift UI, the UI kit, the foundation, the whatever.

Geoff:

And then each of those has a dozen or more different attributes. So there's a lot of things that you can change on an attributed string.

Peter:

Yeah. The it's a great list. I mean, I think it's got everything in there you're you're likely to want to use. I I admit I haven't you know, didn't try building my own because I just didn't need to. Everything was there, right, for standard text editing.

Peter:

So you've got your button. Right? So let's talk about the action. This is the part that matters here. Right?

Peter:

So in my case here, I, I've got my attributed string, which is resume content. So, you know, to dive into the the code here, resume content and then just dot transform attributes, and then it's gonna expect a range. This is where they've done the homework for you, because you can just say in whatever the name of your attributed text selection is. So in my case, selected text. And it's gonna figure all of that out for you.

Peter:

So then you've just got to put the body, which in this case goes along these lines. Okay? So container in. And then the reason we do this is we want to get a reference to the text that we've got here. So, for example, in my case here, let current font equal container.

Peter:

Font. Right? Or default, if it doesn't have any. So now that I've got that set up, I can take that. I'm going to apply some new stuff to it.

Peter:

Right? So in this case, we're going with bold as the example. So I've got, again, another variable here, let resolved equal the current font, dot resolve, and then in fontResolutionContext. And then once we've got that set up, all I got to do is say container dot font equals current font dot whatever attribute we want to apply. In this case, bold.

Peter:

And then we're just gonna say, hey, if it's not bold, make it bold. Right? And if you want to use it as like a toggle button between bold and, you know, back to normal, it's gonna take care of for you. I know that sounds a little bit complicated. I'll put a code example in the show notes.

Peter:

But, basically, that is all you've gotta do to essentially tap in to the API to take advantage of making your own custom toolbars. Geoff, does that make sense? Any questions?

Geoff:

No. That sounds like it's got a pretty powerful set of tools that's available for you. It sounds like you can kinda get in there, get the selection, get the attributes for your selection, find out a bunch of information about the text that you have there, and then be able to manipulate it. So, I don't know. I think that's very cool sounding.

Peter:

Yeah. Yeah. And that is all there is to it. You know, let's say that you wanted to change what I've just described here to italic, for example. All you have to do is change the part that matters.

Peter:

So, where I said container dot font equals current font dot bold, all I would have to do is container dot font equals current font dot italic. Right? So that's where that list is gonna work beautifully for you. If you wanna create a whole, like, row of keys row of buttons for this on each one, you're you're basically gonna do the same thing over and over, but just changing the attribute type you wanna affect. Now, I do wanna talk about an extra part here, but, basically, that is all you need to do to use the API.

Peter:

There's always a however or a but. And the however or and the but on this is, if you are gonna want to work with this as a persistent storage, and I'm gonna guess that the likelihood is you are, that's when things get a little interesting. And I I gotta give a shout out to my mate, Geoff, here, who we worked through this together. So I'm using a CoreData backend, and my my entity for this is set to data. And there are reasons for that.

Peter:

But, Geoff, I'm gonna let you talk about that. Tell us why we need to use the data type for this. So the different types that you can have as fields on a Core Data entity, there's a bunch of the primitive type ones. You've got string, you've got booleans, you've

Geoff:

got your ints and your floats and your doubles. You've got some slightly more complicated ones like dates and UUIDs and URLs, I think, can also go in there.

Peter:

Yep.

Geoff:

And then kind of your remaining catch all there is data conforms to Swift data or Objective C NS data. And the reason you want to use that here is because you've got a pretty easy way to turn attributed string into data, which is attributed string conforms to Codable. So at the very least, you have the real dumb simple answer of you can convert it to JSON, and you can toss that JSON data into your data field. Now that's probably not the most compact representation of it that you can have, but it is like, here is the extremely simple way of we just need to persist a attributed string, and that that's how we're gonna do it. The more complicated way, the probably slightly better way, but the little bit more finicky way, is that attributed strings have a method on them called exported, and you can provide a UTI, a universal type identifier, to them, and they can export to a couple different types as well there.

Geoff:

I think the most obvious one for that is to use RTF, which just saves it as the rich text format. And then you can stick that into a data field on Core Data as well. Or do whatever else it is that you're doing, you know, if you're storing that in SQLite or you're storing that on just a disk as an RTF file. All of those are options.

Peter:

Okay. So, yeah, that is using this attributed string in the text editor in SwiftUI. I'm really enjoying using it. It is significantly less code than doing it with the third party that I was using, and with less problems, plus the bonus of all the built in goodness that Apple gives you. Right?

Peter:

So, that's what I've been looking at here, this API. And like I say, it solved a big problem for a feature for me. Now I just gotta wait for them to release the OS so I can release my update. So, let me let me throw it across the fence here. Geoff, go for it.

Peter:

Hey, folks. If you like what you're hearing in this podcast and you wanna help this podcast to continue going forward and having great guests and great conversations, I invite you to become a Patreon supporter. You can go to patreon.com/compileswift, where you will get ad free versions of the podcast along with other content.

Geoff:

So what I've been looking into, I haven't yet been able to build a project with. I I haven't really done too much yet that is iOS 26 only so far. I'm about to start that with Black Eyeliner very soon. But so I'm not gonna be able to get as in-depth with my experience with it so far, but let me talk through kinds of the things that we have available. And what I've been digging into is the improvements to AppIntense.

Geoff:

This is all of your integration with shortcuts, but also integration with different parts of iOS and, well, all of the OSs themselves. And I think the really cool big new one that I'm really, like, hunting for a place to use is interactive snippets. And what that is is when you run a shortcut, especially if you're running a shortcut in the background, it gives you the ability to put up a view, almost like a micro view of your app. And it's now interactive in iOS 26, where you can actually have a user tap a button or take an action, and that action actually does something. Now, it's a little bit limited in the UI.

Geoff:

If you're familiar at all with building interactive widgets, which I think we've been able to do for about two years now, it uses a lot of the same limitations as that, which is that you can basically say, oh, there's a button here and hitting this button performs this action. And the fun part is this is app intents all the way down, which is that your button actions inside of an app intent snippet are themselves triggering other app intents.

Peter:

So does that imply that you can sort of chain these things together?

Geoff:

Yeah. You could have an app intent that displays a snippet that has a button that then displays another snippet. So I believe that that it is is possible to do that. So you can kind of build these actions that have this multi step UI to them. Alternatively, another thing that you could do that that actually works and probably is a better user experience is that you can actually have the button or the action that you call inside your snippet update the current snippet.

Geoff:

So you can have some kind of like semi interactive UI in there. It's all very static. You can't have like sliders, for example, that act on a completely user interactive basis, but you can have a button that favorited a video, for example, and then it updates and you've got a little heart symbol on that video. You can do stuff like that where it's actually updating the snippet in real time, but it's still kind of just a limited peek into your app.

Peter:

Right. Because, I mean, I I would think, you know, you don't wanna make these things overly complex either. Right? So I don't know. I don't know Apple's intent here.

Peter:

I'm sorry. That was not an intentional pun. It I I promise you

Geoff:

Not intentional?

Peter:

Not intentional. Yeah. Exactly. But what I was gonna say was maybe their intention was to force you to keep them simple by putting these restrictions in place.

Geoff:

I I think it's it's somewhat keeping it simple and somewhat and maybe even more somewhat keeping it not very resource intensive in very similar to the ways that interactive widgets are, which is that you don't wanna be booting up a whole process. It's just kind of rendering a SwiftUI hierarchy for you.

Peter:

Gotcha. Yeah. And and you want like you said, you know, the idea here is the these are quick actions. Right? These are quick things.

Peter:

Yeah. Yeah. You're not like, oh, I'm gonna spend a lot of time working with this. Right? And and it's certainly for me, when I think of, like, you know, widgets and intents and all those kind of stuff, it's a very quick, like, purpose driven thing and I'm moving on.

Peter:

Right? I'm not gonna live with this thing for for a long time.

Geoff:

This is not an app that I've built for myself. This was more of a shortcut that I built for myself a while back. It requires me to enter data into the shortcut that is displayed. And I can imagine that if I had an app for that, that that would be something that I would be able to do there, which is just very quickly kind of say, oh, I'm displaying a view from my app, and I want to enter some data, and then hit submit, for example, and that that does something. Now the way that this is done, the way that you actually interact with this is by just returning a different type from your standard intent.

Geoff:

And so if you've got an app intent, if you ever built anything with app intents before, you know that the perform action, you return a result, and that result starts with some intent result. And then you can stick a bunch of other protocols on the end of that. A common one that you have is returns value, which allows you to, you know, actually pass forward another value in, like, shortcuts or something. It kinda passes it on to the next action. You've also had for a long time open intent, I believe is what it's called, which will actually just straight up launch your app.

Geoff:

So if you run something in shortcuts and then you're like, oh, but I actually want this to now, like, edit something in my app, that's the open intent, and and it'll open your app. The one that they're providing for this is shows snippet. And what that means is when you're done performing your action of your built in original intent, you say show snippet, and you return the snippet type that you want to present. And that kinda renders, populates, puts in all your data, all of that, and then displays that view to the user. And so that's the way the snippets have actually worked for a while.

Geoff:

But the new thing that you've got in this year is that you can have buttons that take as a parameter an action, and that action is itself another intent, which works very similar to the way that interactive widgets do. And so when the user sees that snippet and they tap that button, it then performs that action and can do something in response. And if you need it to rerender your snippet because you've changed something, then you just call a simple reload method. And that causes your snippet to reload with whatever new data you have available. And so snippets is kind of the big one.

Geoff:

We did get a couple additional things with AppIntense this year. They gave it some little developer improvements that make it easier for you to, like, decide what data that you have in an intent. They added a undoable intent, which allows you to, like, do something with the user. And then if the user goes, wait, wait, wait, hold on. There's a standard UI for having an actual undo method.

Geoff:

Previously, you had the ability to ask for confirmation and it could say yes and no. Now you can actually provide like multiple choice. Lot of cool, fun, intense stuff this year. And intense is eventually, if we ever actually get it, supposed to be the backbone for Apple Intelligence. But I say to people, like, start looking into this now because the amount of things that it can do even without Apple Intelligence being ready yet is pretty big, and it's it's really a cool thing.

Geoff:

And Apple's obviously pushing it pretty hard. So, definitely look into the improvements that they've made this year, and all of the stuff that they've had for three or four years now.

Peter:

Well, and I think you make a good point there, right? Because when you say, like, you know, Apple's pushing this hard, we've come to learn over the years. There's usually if we don't know now, there's a hidden reason for it down the road. Right.

Geoff:

I was gonna say that the big one this year that really unlocked, I think, bunch of stuff and will unlock even with a lot of the snippets and whatnot, is the fact that intents now show up in spotlight on the Mac. So even if it's just the Apple silicon compatibility layer running your iOS app there, you have the ability to kind of like, a user can just hit command space, type in something, and then just use your app from anywhere in the system very quickly. And so, you know, it's another chance to get your app in front of users all over the place. So definitely look into AppIntents. Snippets is a cool new feature that they've added to it this year, but there's a lot of cool stuff that they've always had and will continue to have.

Peter:

And we did some episodes on the this very subject. Right? So, if you are wondering, well, why should I offer this in my apps? Hey. We we got that covered.

Peter:

Go back and check the archives. We'll tell you why it's important and how you it's essentially free marketing for your app at this point. Right?

Geoff:

So, yeah, those are our two favorite APIs announced at WWDC this year. And, obviously, that's not even beginning to think about scratching the surface of everything that we got this year. There are a lot of cool things that, you know, I've been meaning to look into, that I know Peter's been meaning to look into, all of the new foundation model stuff. I'm particularly excited about the AlarmKit API. There's all kinds of fun new things that are going to be available in iOS and macOS and all of the OS 26.

Geoff:

And so, a, go check out especially all of the WWC videos that start with what's new, and let us know in our Discord or in podcast review or by contacting us at compileswift.com, what are your favorite APIs? What are the things that you saw at WWDC that you're really excited about? And hey, maybe we'll talk about those on a future episode.

Peter:

Also, on that note, if you've got questions or topics that you would like to hear us talk about and we feel like we are suitably knowledgeable on them, by all means, reach out and

Geoff:

suggest Or can become suitably knowledgeable on them.

Peter:

Or can become, as we have demonstrated. It is possible for Peter to learn something between recording episodes. Let us know. Same methods, write compilesswift.com and all that good stuff.

Geoff:

So, Peter, I think that's it for this episode of the compiles swift podcast. Where can everybody find you?

Peter:

Yeah. You can find me at peterwitham.com. And, of course, by now, you know where to find this podcast. But do we know where to find Geoff? Let's find out.

Geoff:

As as always, you can find everything that I do at cocoatype.com.

Peter:

We hope this has been helpful, folks. If nothing else, go what like Geoff said, go watch the videos. Right? Because playing with these APIs really makes us wanna go and look at some more of them. It's all the things you don't necessarily hear too much about at the conference.

Peter:

Alright, folks. That's it. We will speak to you in the next episode.

Two of our favorite WWDC25 API's
Broadcast by