-
코딩 실습: Swift 및 SwiftUI로 빌드 시작하기
Swift와 SwiftUI로 앱 개발의 기본 사항을 알아보세요. 이 온라인 코딩 실습에서는 Xcode의 iOS 데모 앱에서 간단한 보기를 빌드하고, 입력을 캡처하기 위한 텍스트 필드와 사진을 추가하고, SwiftData를 사용해 정보를 저장해 봅니다.
리소스
-
비디오 검색…
Hi, I'm Leah. I'm a technology evangelist on the Apple Developer Relations team. I help developers learn about technologies like SwiftUI so they can build the best apps for Apple platforms. Hello everyone! I'm Lucas, an instructional designer on the education team. I build resources for developers to learn everything from app development fundamentals to the best practices on Apple platforms.
We're streaming to you live from the Apple Developer Center in Cupertino, and I want to welcome everyone who's joining us online from all over the world.
Today we'll introduce you to a brand new Code-along that we recorded earlier. It's based on the Develop in Swift Tutorials. You can follow along with Lucas and start building an app from scratch Throughout the code-along there will be an opportunity to submit questions through Slido. We have a team of Apple engineers who are eager and ready to answer your questions, whether they're about developing for Apple platforms or the technologies covered in the Code-along.
After the code-along, Lucas and I will come here back on stage to answer some of your questions live.
The tutorials we're showing today were released alongside an exciting announcement. The Swift Student Challenge 2026 will open February 6th. We're thrilled to invite students from around the world to participate. It's a great opportunity to showcase your skills and your creativity. If you're passionate about solving problems and want to develop your technical skills, build an app. It can be on a topic of your choice. The Swift Student Challenge submissions will be open February 6th through the 28th, so now is a great time to get ready! Today's Code-along has something to offer for everyone. Whether you're new to building apps or already have experience and are interested in gaining exposure to new frameworks.
Today I'll go through a Develop in Swift Tutorials available on the Developer.apple.com webpage.
The tutorials offer step by step instructions to build apps. You can go at your own pace and learn skills like how to design an app, how to build a user interface, how to use new frameworks, and much more.
I'll follow every step of the tutorial. I'll share why I'm doing each step along with some helpful tips. So follow along to start building a demo habit tracking app called Grateful Moments.
During the code-along, remember to ask questions in Slido so our team can support you. I'd also like to shout out another resource not just for this code-along, but your entire journey as a developer. Anytime you have a question, check out the Apple Developer Forums at Quad LED True Tone flash. There are forums for many topics, from frameworks like SwiftUI and SwiftData to different platforms like iOS and visionOS, and even community aspects like the Apple Developer Program and the Swift Student Challenge.
Even if you don't have a question, the forums are a great way to learn from other people's questions and familiarize yourself with Apple's technologies.
Okay, now it's time for the main event. Settle in and get ready to code along with Lucas. We'll be back here soon to reconnect and answer some questions.
Hello everyone and welcome to this Code-along where I'll start building an app with Swift and SwiftUI using Xcode. My name is Lucas. I'm an instructional designer on the education team here at Apple, and I'm excited to guide you in creating a fully interactive view of a demo app.
I'll build a SwiftUI view at textfields, dividers, buttons, the ability to show photos, and more. But before I start, make sure you have Xcode installed on your Mac. Apple provides free resources to help you learn app development. Be sure to check them out at developer.apple.com.
Today, I'll be using the Develop in Swift Tutorials to start building the GratefulMoments demo app. An app to help you with a habit of being grateful. You can learn how to code this entire app and much more in the Develop in Swift Tutorials. They were created for anyone who wants to start developing for Apple platforms. If you're new to app development, this is a great place to start.
Begin with app design, where you learn how to transform your ideas into interactive Active prototypes ready for testing. I recommend this tutorial even if you are an experienced app developer.
The SwiftUI and data modeling tutorials introduced the fundamental concepts of Swift, SwiftUI, and SwiftData. They will get you ready for the app development tutorial where the Grateful Moments demo app is built.
You can also explore advanced topics in the machine learning and spatial computing tutorials, and finally understand how to prepare and submit your app with the app distribution tutorials. And before I begin, I'll go over how we here at Apple came up with the Grateful Moments demo app.
People seem to enjoy and are motivated by tracking their habits and being grateful for the things that you have and experience is a great habit to have.
We then use all of the concepts presented in the app design tutorials to plan, prototype and design the app. Then we went from brainstorming ideas to using wireframes and organizing them into a working prototype.
We tested the prototypes with people, got feedback, and refined the design. We repeated this process until the results were meeting and sometimes exceeding expectations.
The tutorials show you step by step how to create this demo app from start to finish. It includes several features such as badges and streak indicators for encouragement, and the ability to add a photo to better capture and illustrate the moment, and much more.
Today, I'll start the demo app by building the entry view. I'll use several SwiftUI views that will make using the app feel familiar. These views include text fields to capture people's input as text dividers to visually separate items on screen, buttons to trigger actions such as closing a view or saving an entry. The photo picker to allow people to select a photo from their library and use it as an image in the app.
And to save all this information, I'll use SwiftData. SwiftData enables me to add data persistence to the app with minimal code and no external dependencies.
I'll be using macOS Tahoe and Xcode 26 in this session to code along with me. You'll need recent versions of both for Mac OS that is macOS Sonoma or later, and for Xcode that is Xcode 15 or later. You can get Xcode from the App Store. It will offer the latest version compatible with your version of Mac OS. Okay. I'll begin by opening the Develop in Swift Tutorials page. Here you'll find all the code and instructions I'll be using throughout today's Code-along session. I'm on the main page of the Develop in Swift Tutorials. I'll scroll down until the left navigation menu shows up. I'll click on App Development to expand it. Views and Data Storage chapter. And right here in the middle of the chapter we have the collect Model and Store data tutorial.
There are five sections in this tutorial. First I'll create a project. Then I'll build a data entry view. I'll add a photo picker and create a data container. Then I'll add the save and cancel features to the project.
Finally, every tutorial has some multiple choice questions at the end. It is a great way to check your understanding. Each section has a clear goal and concrete steps to accomplish it. Before each section, I'll go a little deeper and describe the main takeaways. Now each section has steps. Each step has a short explanation on the left and a preview on the right.
Similar to when a step involves code, the preview is displayed on the right. The code created in that step is highlighted and the file name is shown at the top. I'll copy and paste code from the tutorials to Xcode throughout this code-along. However, consider typing out the code. It will help you get familiar with the language and the tools available to you in Xcode like code completion.
I have the default automatic code completion turned off in this section to avoid distractions, but I trigger it often using the escape key. Okay, time to start section one create a project. In this section, I'll create a new iOS project in Xcode. Fill the asset catalog with images and colors I'll use in my app, and I'll add some structure to the project by creating folders to organize my files. These are things that I do almost every time I start building an app.
I'll start by creating a new project in Xcode with the appropriate options. So I'll go to the tutorial and scroll to section one. Step one to find the options I need for my project.
I'll leave this here for reference and I'll switch to Xcode.
Here I have the Welcome to Xcode window open. If you don't have the screen, click on window, then welcome to Xcode.
You can also use Command Shift one to open this window. I'll close the menu and click on Create New Project.
I'll make sure iOS is selected as my template and I'll select app as the application type. And next.
And here are the options. I'll go back to the tutorial to copy the product name.
Grateful Moments I'll use command C to copy and command V to paste.
You can leave team and organization identifier to its default values, but make sure that the interface is set to SwiftUI over here and the storage is set to none.
I will use SwiftData, but I'll add it manually later. Instead of using Xcode's template, I'll click next and select the desktop for the location of my project and click create.
I'm going to put Xcode in full screen mode and adjust the window sizes a little bit.
Great. The project loads with a preview of your app, a globe symbol, and the text hello world! If you don't have the preview, click on the Adjust Editor Options button on the top right and select canvas. You can also use the command option return shortcut to open and close it.
Great! I now have a new iOS project called GratefulMoments saved on my desktop showing a globe symbol and hello world! Now I'll add some colors and import some sample images I'll use later in my app. So I'll switch to the tutorials.
I'll scroll down to step two where the sample images are added. I'll continue to scroll down to step three where new color is created. I'll keep going to step four where the colors parameters are set. And finally I'll scroll to step five where three more colors are added.
The purpose of creating these name color sets is so that they can be referenced in code easily.
The same way you can easily reference the imported images by their file names.
So I'll switch to the tutorial and I'll start by downloading the project files using the link all the way at the top of this page. I'm going to scroll up and click on Project Files and make sure that it's being downloaded. Great. I'll go to Xcode. In Project Navigator on the left, I'll click on the assets file to open the Assets Catalog. This is where you manage your project resources such as images, colors, and data files.
I'll start by adding the sample images I downloaded. So I'll open the downloads folder. And if you see a zip file inside of a folder, double click on the zip file to expand it. Now I'll open this folder and expand the samples folder to show the images.
I'll then drag the samples folder over to Xcode and place it here in the Assets Catalog.
Great. I now have three images I can use in my app. Now I'll add my colors. I'll first click on some white space here on the assets catalog to unselect the samples folder. And then I'll click on the plus button down here and select folder and rename it colors. I'll hit Return to Accept.
And now I'll add a new color set by clicking again on the plus button down here and selecting Color set.
I'll name it Ember.
By default, you can configure a color for any appearance and a separate color for dark appearance.
I want the same color for both options, so I'll open the attributes Inspector.
I'll use the hide or show the inspector's button on the top right and clicking on the rightmost tab. I can also use the command option for shortcut to open the attributes Inspector. Next, in the color set attributes in the appearances section, I'll change the selection to none.
Now I only have one color swatch labeled universal, which will be used for all appearances.
Now I want to give you a great tip for when you want to customize your colors. I'll click on the universal Color swatch, and in the color section I can change the input method.
I can select floating point to display color sliders I can change.
I can also click on Show Color panel to select a color.
However, the tutorial gives color values in eight bit hexadecimal format. So I'll close the color panel and I'll select eight bit hexadecimal again and I'll switch to the tutorial. I'll scroll to step four while I'll copy the hex value provided.
I'll switch to Xcode and paste it in the hex field.
I'll press Tab to accept it. And there I have my first color.
I still have three more colors to add, so instead of adding each one of them by using the plus button each time, I'll duplicate the Ember color three times.
So let me do that. I'll click on Ember and duplicate it three times.
Now I'll switch to the tutorial and scroll down to step five, where I have my three new colors.
Ocean, Ruby and Sapphire. So I'm going to switch back to Xcode and type these in ocean.
Ruby.
And Sapphire.
Great. But they all have the same color. Let me fix that.
I'll first copy the hex value for Sapphire to change it. I'll click on the color swatch and paste it in here in the field. Great.
Next one is Ruby. I'll copy the hex value. Click on Ruby, the swatch and the field.
Great. Last one. Ocean Hex value. Click on ocean, click on the color swatch and paste in the hex value.
Great! I now have all the colors for my app. Now all system UI components are blue by default. Buttons, links, and other elements.
I want them tinted Ember instead. To do that, I can change the app's accent color, so I'll first select Ember as my color. I'll click on the swatch and use command C to copy.
Then I'll click on Accent Color, click on the swatch and paste my Ember color.
Done. My app will now show the Ember color instead of the default blue on buttons, links, and other UI elements.
The final step in section one is to add some structure to the project by creating folders to organize my files.
I'll only use a couple of these folders in this session, but I'm thinking ahead and know that my project will have more files. I'll create the custom views folder for complex or very specific UI files. The Logic folder for code related to my data model. The models for my data types. The tabs folder for holding two other folders. The Achievements folder for views that show the badges and the streak indicators people can earn when using the app. And the moments folder for views that deal with the entries people create.
I'll switch to Xcode. I'll first select the Grateful Moments folder and right click and select New Folder.
I'll name it Custom Views.
Now I'll use command D to duplicate the folder five times one, 12345. I'll switch to the tutorials and on step seven I have all my names, so I have Logic.
I have models and tabs.
And I have the Achievements folder.
And the moments folder.
Both the moments and the achievement folders belong inside the tabs folder.
Okay, perfect. Now I have a well-organized project structure that will make development much easier as the app grows. And that's it for section one. I have my Grateful Moments project set up.
My assets are ready to go, including the accent color, and I'm confident that as I add new files, I'll know how to organize them. This is a great start. Now on to section two build a data entry view. I'll build the first view of the demo app, the view where people create their Grateful Moments. I'll add basic navigation so people know where they are in the app, and I'll make it fully functional so people can write what they want for their moment of gratitude.
I'll start by creating a new SwiftUI view file named Moment Entry view in the moments folder. So I'll switch to tutorial and scroll down to section two. Step one.
Step one creates a new view called Moment Entry view, so I'll copy the name of the view here on line three and I'll switch to Xcode.
I'll select the moments folder and I'll use command N for a new file. Now Xcode has templates that provide a basic code structure for you to work with, so I'll make sure iOS is selected. And in the user interface section I'll select SwiftUI View template and click next.
I'll name it Moment Entry View. So I'll simply use command V to paste and click create.
Great. I now have a SwiftUI view template which imports SwiftUI, declares the view struct and has a body with the hello world text.
Then the preview macro calls my view so that it's displayed on the canvas on the right.
I'll switch to the tutorial and I'll scroll down to step two.
Now I want to create a basic placeholder structure for my view. I want to keep the code in the body view easy to read, so I'll create a variable called Content Stack that will encapsulate the layout in an easy to understand component. So I'll copy the content stack declaration from lines 8 to 15 here on the tutorial.
Use command C to copy and I'll switch to Xcode.
I'll paste the content stack below the body variable.
And in the body, I'll replace the Hello World text with content stack.
So looking at the content stack, I have a vertical stack or a VStack with two text views, one for the moments title and one for the note. I can see them both on the preview here on the right. The VStack arranges its Subviews in a vertical line aligned to the text leading side. Note that the alignment can also be center and trailing.
This automatically updates if you are using a right to left language. Very convenient.
And to read more about how to arrange your views, check out the Layout and Style chapter in the SwiftUI tutorials. Another great resource is Apple's Human Interface Guidelines, which can help you design for any Apple platform. So switch to Xcode. I now have my placeholder views in place. They are a great way to quickly place elements on the screen, and I always start with these simpler elements to establish my view structure.
I'll go to the tutorials now.
I'll scroll down to step three.
Now, since I know my view is going to grow vertically, I want to add a scroll view to ensure people can see all of my view, even if it goes beyond the screen. Another benefit of using the scroll view is that it will dismiss the keyboard automatically in case it's scrolled off screen. And that's what the scroll dismisses keyboard modifier does here on line eight.
I'll copy its declaration and I'll switch to Xcode.
I'll first type scroll View right above the content stack. In the body scroll view, I'll use escape, accept the suggestion, and open and close my curly braces. Says.
And finally, I'll paste in the modifier. Now I have a quick tip. Use command option three to open the Quick Help Inspector. It's a great way to learn more about your code and get familiar with the documentation. I want to learn about the scroll dismisses keyboard, so I'll place my cursor on it and the quick help updates with information about it. You can do this with any object you want to learn about. Okay, I now have my view structure with placeholder elements and a scroll view to make my view work as people expect it to.
Now I want to let people know where they are in my app. I also want my view to be in a container that enables hierarchical navigation in my app. Think of it as the backbone for moving between screens.
I'll go to the tutorial. I'll scroll down to step four where I have the navigation stack encapsulating the scroll view. Here on line five and a navigation title for the view. Here on line ten.
So I'll copy the navigation title and I'll switch to Xcode.
I'll first type navigation stack right above the scroll view.
I'll open the curly braces and go down to the line right below the scroll. Dismisses keyboard, paste the navigation title and finally add the closing curly brace. Now my view has the grateful for title and my view is ready for navigation, which I'll implement later on. Great. My views navigation is all set up with a navigation stack and navigation title to inform people using the app where they are.
Now I need to provide a way for people to write what they want for the title and the note of their moment of gratitude. So I'll switch to the tutorial. So I'll scroll down to step five, which adds a text field for the title of the entry and a divider to visually separate the elements on screen, and step six adds the text field for the note of the entry. I'll first copy the declaration of the two state variables up top on lines four and five, and I'll switch to Xcode and paste it up top. After I declare my moment entry view, the state property wrapper indicates that when these variables change, the interface is automatically updated.
So I'll switch to the tutorial again, and I'll first copy the text field for the title on lines 19 to 23.
I'll switch to Xcode and paste it over the placeholder title text in the content stack.
So the text fields text parameter binds to the title and provides a placeholder text element. The title required text gives people context about the field. The text field is then stylized like a title to demonstrate its importance in the visual hierarchy. It uses the font modifier to set a large and bold font. Then the padding modifier adds some space above itself, 48 points to be exact. Now I'll add a divider below the text field to visually separate it from the note below. Okay, great. I now have the title taken care of, so I'll switch to the tutorial and copy the text field for the note on lines 26 to 28.
I'll switch to Xcode and replace the placeholder text for note.
Now, since I want to allow people to enter notes that are longer than a single line of text, I'm using a slightly different initializer. For this text field. I first provide the placeholder text log. Your small wins, then I bind the text to my note variable, and then the axis dot vertical parameter enables multi-line text input and allows the text field to grow vertically. After that, the multi-line text alignment modifier aligns text to its leading side, and finally, the line limit ensures that the field has space for at least five lines and can grow up until the maximum value an int can have. This five line minimum is a great way to let people know the field accepts multiple lines. To test this, I'll run the app in the simulator. I can click on the run button at the top of the navigator, or use command R to run the project.
Once the app loads in the simulator. Oh wait, I did not expect to see this. Hello world! I was expecting to see my moments entry view.
Oh yes, I didn't actually include it in my app, so I'll go back to Xcode. I'll click on the GratefulMomentsApp file which is the entry point of my app. The main macro here, along with the app protocol, mark this file as the entry point for my app. Now I'll place my cursor on Contentview and use Command Forward Slash to comment the line out.
Then I'll add my moment and review. Okay, I'll run the app using command R, and I can now test the multi-line text field by adding a long piece of text. So I'll type in.
I'm having a great time with this code-along. I'll select all and copy and paste the text to see my text field growing because of the line limit I set on it. Note that in the simulator I can show or hide the software keyboard using the command k. I can also go to the menu bar and select iOS keyboard and toggle Software keyboard.
Now I will swipe up and down. Now I'll swipe down until the keyboard is dismissed. Without this modifier, the keyboard would remain visible. This blocks the view of some of my content. Now people can use a text fields to give their moment a title and write a note about it, which can be short or very detailed. Amazing! That marks the end of section two where I have the first functional view of my app. I have a title that tells people where they are in my app, and I have a way to navigate using the navigation stack. I also have fully functional and styled text fields to capture people's input, and as a bonus, I've set up the project to enable testing in the simulator. In section three, I'll add a photo picker so that people can use their own photos and associate them with the Grateful Moments. I'll build a placeholder view to use when there is no image selected. I'll use the PhotosUI framework to present the system photo picker. Then I'll load the selected image from the photo library into the app. I'll first create a placeholder view that serves as an indication that a photo can be added. So I'll switch to the tutorial.
I'll scroll down to section three.
Step one where the PhotosUI framework is imported necessary to present the system photo picker. The PhotosUI framework provides basic access to the photo library on the device. It handles permission requests and manages those interactions for you. I'll go ahead and scroll to step two, where the photo picker variable is declared along with the image my placeholder. So I'll copy the code from lines 18 to 25 and switch to Xcode.
I'll first open my moment entry view file, and up top I'll import the PhotosUI. Why? Then below my body, I'll paste the photo picker variable.
And then I'll call it in the content stack. So I'll copy photo picker, go down to the content stack, and right after the note text field I'll paste in photo Picker. Great. Now I have my placeholder image. It uses an SF Symbol called Photo.badge.plus.fill. Where did I get that from? I got that from SF Symbol. They provide thousands of consistent, highly configurable symbols that you can use in your app. There are great in toolbars, tab bars and context menus. You can download the SF Symbol app from Apple's developer website. The app is a great way to browse which symbols are available for you to use in your app. Okay, I'll switch to Xcode to explain the modifiers I have on the image, I'll scroll back up to it. And now, since SF Symbol behave like text, I'm able to use text modifiers such as the font modifier here set to large title. I'll select the large title, delete it, and press escape to list the other options I have.
I'll select headline.
And notice how my photo symbol is much smaller. I'll undo this change and put it back to large title.
Next, the frame height is set to 250 points and the max width is set to infinity.
I'll come in. Both of these line out to demonstrate their effect in the preview pane. The frame modifier is essential to determine how much space you want your views to occupy on the screen, so I'll remove the comments from the frame lines. And now comment the background modifier. The background modifier allows me to add a color to my views. I'll uncomment the line and note that the color is initialized with 40% white and 32% opacity. It gives this light gray with some transparency, and I'll comment the line again, because I want to demonstrate how to use the system colors and the color sets I defined at the start of the session. So I'll type dot background and inside the parenthesis I'll type in red. This is a system color, but I can also use the color that I defined in my color sets the ocean color for example.
I'll undo all this.
And finally the clip shape modifier literally Clips the views with a shape. I'm using the rounded rectangle shape with a corner radius of 16 points. Shapes are a great way to enhance your interface with different kinds of rectangles and circles.
For example, I can change the rounded rectangle to a capsule shape.
Great, right? I'll undo this change and keep going. Okay, I now have my placeholder view stylized and ready to be part of the photo picker implementation.
Next, I'll use the PhotosUI framework to present the system photo picker that allows people to select an image from their photo library, so I'll switch to the tutorial.
I'll scroll down to step three and on line seven, an optional photo PhotosUI item named Newimage is declared PhotosUI item is the data type returned by the photo picker, which I'll handle shortly. So I'll copy the line line seven and switch to Xcode and paste it right after my other variables at the top of the code.
I'll switch back to the tutorial, and on line 20, the photo picker is added to encapsulate the image. I'll copy this line and switch to Xcode and paste it right above the image.
In Photos Picker and I'll add my closing braces. The photo picker binds to the new image variable to store the selected image. The image now acts as a button that presents the photo picker, which I'll go ahead and test on the preview. I'll click on the image area Nigeria and the photo picker is presented. I'll select the photo. The picker is dismissed automatically. However, no photo is displayed. This is expected since there are a few extra steps to get there. But for now, I'm happy that I can present the system photo picker and allow people to select an image from their photo library.
Now I want to update my interface. When an image is selected, I'll need to look out for changes of the new image variable. A photo picker item and extract the image data from it. This conversion allows me to use SwiftData to store the image and to convert it to a UIImage, which I can present using SwiftUI. So I'll switch to the tutorial. I'll scroll down to step four.
Which adds the on change of new image modifier. It is triggered any time the value of new image changes. In other words, when a photo is selected in the photos picker. When that happens, the guard let statement on line 29 makes sure new image has a value. In other words, it's not nil. So I'll scroll down to step five, which declares an image data variable on top. This is an optional datatype which will hold the data of the converted photo picker item.
This occurs on line 32 within an asynchronous task.
It transferred the image from the photos library to the app. Now image data is set by using. Try to handle any errors and await to suspend execution until the image data is loaded. The image is loaded by using load Transferable with data as the type. The Transferable protocol allows objects to be shared or transferred between apps. In this case, I'm asking the photos picker item to give me the image as a data type.
Okay, I'll start by copying line seven. The optional data declaration.
I'll switch to Xcode and up top I'll paste in the image data right above the new image variable, just to keep it consistent with the tutorial. I'll switch back to the tutorial and copy the entire on change modifier from lines 29 to 34.
I'll switch back again to Xcode.
And paste it below the photos picker.
Okay, image data is taken care of. Now the interface needs to be updated to show it. So I'll switch to the tutorial.
I'll scroll to step six, which adds a group around the placeholder icon, carrying with it the clip shape. I'll continue to scroll to step seven, which adds an if statement to show a selected image if there is one, or show the placeholder icon if there is none.
Now the group allows me to apply a modifier to all views encapsulated in it all at once. In other words, the clip shape will be applied to both the selected image and the placeholder icon. The if first verifies if there's an image data and then converts it to a UIImage. If both succeed, an image is displayed and stylized, otherwise the placeholder icon is displayed.
Okay, I'll copy the entire group code from lines 22 to line 35.
I'll switch to Xcode and I'll paste it over the entire placeholder image code.
Great. My photo picker is ready for testing.
I'll click on the image area.
I'll select the photo and it works. The image is displayed instead of the placeholder icon. Now on line 32, the resizable modifier makes the image stretchable. Without it, the image uses its original pixel size and won't adapt to different container sizes. Also, it must come before any scaling modifier. The scaled to fit modifier scales the image uniformly, maintaining its aspect ratio.
Okay. My view is looking great now, and I'm transferring the selected image from the photo library into my app. And I've reached the end of section three. My app is really coming together. I now have a placeholder view displayed when there is no image selected. I've used the PhotosUI framework to present the system photo picker, and I've loaded the selected image from the photo library into the app.
Now I'll start section four. This is the biggest section of them all and is crucial for the app. Create a data container.
I'll use the SwiftData framework to set up persistence in my app.
I'll build a data model that captures the information for each Grateful Moments.
I'll also create some sample data I can visualize in SwiftUI. Previews are a great way to test the layout of my app. Then I'll create the necessary infrastructure to handle my data and connect it to the app.
I'll start by creating my data model the moment class. I'll switch to the tutorial.
I'll scroll down to section four.
And scroll by steps one, two, three and four. That gives me the complete code for the moment class. For reference, now I'll switch to Xcode, where I'll start by creating a new file for the moment class.
I'll click on the models folder and use command N to create a new file.
I'll make sure iOS is selected up top, and in the source section I'll select Swift file, which gives me an almost blank file. I'll click next and name it moment and click create.
Okay. File created. And I'll start by importing SwiftData and UIKit, which I'll need for handling UI images.
So I'll duplicate the foundation import I'll import SwiftData, and I'll import UIKit.
Next I'll declare the class moment.
I'll open and close my curly braces. Now I'll add the model macro above the moment class to register it with SwiftData.
Okay, now I have an error because I can't have an empty class without an init function, so I'll start by declaring the class properties, which I'll copy from the tutorials. So I'll switch to the tutorials and I'll copy line seven through ten.
I'll switch back to Xcode and inside the class moment I'll paste in my variables.
I now have a title and a note variable to hold the text people enter. I have image data to hold the image that people can add to a moment, and a timestamp to know when the entry was created.
Now to create the init function, I'll start out by typing init. I'll hit escape and based on the variables I just declared, an almost perfect init function is suggested.
I'll accept it using return.
Pretty cool right? I have all my parameters and all of my instance properties self, dot, text, self, dot note, and so on. Being set, the init function requires a title and a note, while image data is optional, defaulting to nil.
Now I said almost perfect because I want to make the timestamp parameter optional as well. I want to give it a default value of now, so after date I'll set it equals to dot. Now that now is a shorthand for the static method date.now. It is only allowed if Swift can infer the expected type, and that's the case in my init function, where the timestamp parameter is explicitly declared as a date.
I'll switch back to Xcode and my init function is ready to be used. Now I need to add one more thing to the moment class. Note that image data is a data object and not a UIImage object that SwiftUI can show on the screen.
SwiftData can only store information of certain types, and UIImage is not one of them. SwiftUI views can only show certain types of objects, and data is not one of them.
So I need a convenient way to safely convert the data into a UIImage. I'll switch over to the tutorial, and I'll copy the declaration of image from lines 19 to 23.
I'll switch to Xcode and I'll paste the code right below the init function.
The image variable is an optional UI image and is computed by applying a flatMap to image data.
flatMap returns nil if image data itself is nil. In other words, if image data has no value, image is set to nil.
Now if image data has a value, then the closure is called and a UIImage is initialized using the unwrapped image data represented by the dollar zero. If for some reason the UIImage initialization fails, it will return nil. If all goes well. The UIImage is returned.
Now the same result can be achieved by using the if let pattern. It first checks if image data has a value. If it does, it returns a UIImage if not, it returns nil.
The flatMap elegantly handles both nil image data and invalid UIImage initializations in one function. It's a bit more concise. However, they both provide the same results.
Great. I now have a custom initializer for the moment class.
Now I'll provide my SwiftUI preview with sample data.
Every time I make a new view from my app. I try to think about the different kinds of data it can represent.
I make samples of data that could exist in my app, and try to represent different edge cases to make sure my UI handles everything. As I'd expect with SwiftData, I can create sample data and inject it into my app for testing in SwiftUI previews and to keep my code organized. I'll create an extension of the moment class. An extension is a great way to add new functionality to an existing type, even if you don't have access to the original source code. So below the moment class, I'll declare an extension of the moment class.
Extension Of my moment class. I'll open and close my curly braces. I'll type static, let sampledata equal and open and close brackets to indicate sample data is an array.
Now static means the property belongs to the type and not an instance of it. For example, my sample data is shared by every instance of the moment class. Instance properties, on the other hand, are private or belong to their instance. Every moment has a different title. Note, image, data and timestamp encode. A static property is called using the name of the class itself. Then the property name. An instance property belongs to an initialized object in the example. Here, the instance property title belongs to my moment. An instance of the moment. Class. Okay. Now I want to give you another quick tip. The sample data array needs to be populated with example moment objects. So I'll start typing moment.
And use escape for code completion. I'll select the moment title. Note initializer and hit return to accept it. That's great. However, only the required parameters are filled out. I'll undo and use escape again to select the initializer. But this time I'll use option return. Now I have all the parameters available to populate.
Fortunately, I don't need to do this manually. The tutorials have some sample data available to use. So I'll switch to the tutorial in step four, the sample data array is created with a few different kinds of moments. So I'll copy the entire extension from lines 26 to 56.
I'll switch to Xcode and paste it over the entire extension I typed in previously.
Note that the first moment in the sample data array has a short title and a short note, but no image.
The second one has a longer title, a much longer note, and an image. And the fourth moment has only a title, no note and no image. And above sample data I have three static variables sample, long text sample, and image sample that makes it convenient to get different moments by name. All of this to make it easier to perform my UI tests. Great! I now have some sample data I can use to test my interface in the SwiftUI preview.
Now I'll create the necessary infrastructure to handle my data and connect it to the app. I will place it all into one file, ensuring the logic stays self-contained and easy to follow. I'll switch to the tutorial and scroll all the way down to step ten.
Step ten has the entire code for data container. So I'll copy this entire file.
And switch to Xcode. Well, I'll create a new file.
I'll first select the logic folder.
and use command N to create a new file.
The Swift file template is already selected, so I'll click on next and name it Data Container.
I'll click create.
And then I'll paste the code in and go here to the top of the file.
It starts with two imports. SwiftData and SwiftUI. Then a class named Data container with two macros.
@Observable, which tells SwiftUI to observe changes in the object and instantly refresh the UI. Then main actor to prevent any background thread from accessing SwiftUI or the SwiftData context, which both need to be on the main thread.
Next I have the declaration of the model container, which represents the SwiftData database for my app.
Following that context is a computed convenience variable which returns the model container's main context. The main context is the class that allows me to insert, fetch or delete objects in the database. Providing a shorter name to access an internal property like this is a common pattern I use to improve the readability of my code. Next, the custom initializer accepts one parameter include sample moments defaulting to false for my SwiftUI preview. I'll set include sample moments to true because I want to use my sample data in the SwiftUI preview for the real app. I'll set it to false because I want people to see only the data they create and not my sample data. This is a convenient way to quickly change between testing and real life scenarios in my development environment.
Note that include sample moments is used on line 29 for the is stored in memory only parameter for model configuration. So if include sample moments is true. Is stored in memory only is also true, indicating the data will be stored temporarily. This means that any data you create will be removed once you relaunch the app.
Now when running the real app, include sample moments will be set to false and data will be persisted on disk. In other words, the data will not be removed. Even if you close the app, force quit the app or restart the phone. To delete the data, you would need to delete the app.
Now include sample moments is also used on line 36 to determine if the load sample moments function is called or not. And on line 46, the load sample moments function loops through all the sample data from the moment class, and inserts each moment into the context.
Now I'll go back up to line 24, where I start to configure the model container. Right now I only have one type of data moments, so I'll use the schema to tell SwiftData which data types I care about.
Schema is an array with only one item moment, which returns the type of the object. If I had more data types, I'd add those to this array so SwiftData knows what types to look out for on line 29. The schema, along with include sample moments, is used when initializing the model configuration. Model configuration is then used on line 33 when initializing the model container.
Now usually things are successful, but it's important to handle the unexpected scenario of failure. Initializing the model container and saving the context on line 39 can fail if the device storage is full, or if there's an invalid configuration.
To be resilient, the do block handles the expected case, while the catch block handles errors on line 40, it throws a fatal error. If either of these tries fail, fatal error crashes your app. I use this when I want to be really aware of something going wrong.
Now, since my app relies heavily on SwiftData, I need to catch any related errors immediately. Finally, I need a way to connect my sample data to my SwiftUI preview. I'll scroll down to line 54.
Where a data container is declared for exactly that purpose. It has include sample moments set to true meaning the data is temporary and that the sample moments will load immediately. Great. Now that I have the data, I need to expose it to SwiftUI preview on line 57. To do that, I'll make the sample data accessible to all views, and I'll register the model container with SwiftData. The environment modifier on line 60 injects the sample container data into the environment and makes the data accessible to any view in the hierarchy. And then on the next line, the model container modifier registers the model container with SwiftData. Okay. Almost there. I'll switch to the tutorial. I'll scroll to step 11 where the data container is connected to the app, so I'll copy the entire code for the Grateful Moments app file and I'll switch to Xcode.
I'll click on the GratefulMomentsApp file.
I'll select all the code and paste over it.
A few changes were made here. Import SwiftData on line nine and on line 14. An instance of data containers created. Note that the include sample moments parameter is omitted and therefore defaults to false, which means that when I run the app, I do not load sample moments and the data is persisted in memory. Then line 20 injects the data container into the environment, just like I did before with the view extension. With this, any view within the Content Views hierarchy can access the data container using the environment property wrapper and on line 22. The Data Containers model container is attached to the WindowGroup to register it with SwiftData. Great. This registers my data container with SwiftData and gives me access to all the SwiftData features in my app I'll need later on.
Great! I now have data structures connected to my app. And that's it for section four. I now have the data model for my moment object. I have convenience methods to show sample data in my SwiftUI preview, and I have all the necessary infrastructure to handle my data. Now on to section five, the last section where I'll add save and cancel features. This is where I'll connect all the pieces of my app so people can save their moments of gratitude in the app, I'll Connect my view and the preview to my data container. I'll add, save and cancel buttons on the toolbar for familiar navigation, and along the way I'll introduce some data validation by disabling different parts of the UI until all the requirements are met. I need to access the data container injected in the apps environment and provide the preview with the same. So I'll switch to the tutorial.
I'll scroll down to section five, step one, which on line ten declares a variable named data container.
The environment variable gives this view. Access to the data container instance further down line 68 adds the Sampledata container modifier to the preview, giving it access to the environment and model container. So I'll copy line 68.
I'll switch to Xcode.
I'll click on my moment entry view. Go to the bottom of the file and paste my sample data container below the moment entry view in preview.
I'll switch back to the tutorial and copy line ten.
Switch to Xcode and paste it up top.
Okay, I now have access to my data container in my view and in SwiftUI preview to enable my SwiftData operations. Now I need to add buttons to save the information entered on my view, along with a cancel button on the toolbar for a familiar navigation. I'll switch to this tutorial. I'll scroll down to step two, which adds the toolbar with a button to let people save their entries.
I'll copy the code from lines 19 to 25 and switch to Xcode.
I'll paste the code right below the scroll view modifiers.
And the preview now has a button with a checkmark on the top right of my screen. In the code, the Scroll Views toolbar contains a toolbar item with a confirmation action placement. Now, the toolbar item has a button with a title ad and a system image. An SF Symbol named checkmark. The title ad is not shown because the button is placed in the toolbar. By default, only its icon is shown depending on where I place the button. The default styling changes, so I'll go back to the tutorial. I'll scroll to step three, which starts adding the necessary code to add a moment of gratitude. I'll first need to create a moment using the state variables my view has, so I'll copy the code from lines 22 to 27.
And I'll switch to Xcode and inside the buttons action I'll paste the code. Note that each parameter of the init function is in a new line. This is a matter of personal preference. It makes the code more readable. I get the same results if the initializer was all in one line, so I'll switch to the tutorial and scroll to step four, which import SwiftData up top, enabling me to insert the moment into my model's context on line 30 and then save it on line 32.
Once those operations are successful, the view is dismissed. So I'll start by copying line 11 and I'll switch to Xcode, where I'll first go up to the top and import SwiftData.
And then I'll paste my code before the data container to keep my code aligned with the tutorial.
The SwiftUI environment provides this dismiss action, which closes the current sheet, popover or full screen presentation.
I'll switch to the tutorial.
I'll copy line 30, which inserts the new moment into the context of my data container. In SwiftData, you first stage the changes in memory and track them for validation and relationships. Then you try to save the context and commit the changes to the persistent store on disk. Risk. This ensures data consistency. It allows for error handling if the save fails. So I'll copy the code from line 30 to 36 and I'll switch to Xcode.
I'll paste the code right after I create the new moment down on line 38.
In the do block, I try to save the context and then I dismiss the view.
The catch block handles any errors by doing nothing. In other words, it does not dismiss the view. To allow for another save attempt. I'll switch to the tutorial. I'll scroll to step five where I add my first piece of data validation. If a moment has no title, I want to prevent it from being saved, so I'll disable the app button. If that is the case, I'll copy the code on line 38, and I'll switch to Xcode and paste it after the closing bracket of the button.
This disables the button if the title is empty.
I can now test this in the preview. I'll type in the letter A in the title, and the add button immediately changes from gray to Ember my accent color indicating it is now active. Great. I now have the add button on the toolbar. The button enables saving as soon as the title is not empty.
Now I need a way to cancel out of the view and close it without accidentally losing data. I'll switch to the tutorial. I'll scroll to step six and copy the is showing cancel confirmation declaration on line ten.
I'll switch to Xcode and paste it up top after my other variables. I'll use this variable to control the confirmation dialogs presentation. It's set to false to ensure the confirmation dialog is not displayed when the view opens.
I'll switch back to the tutorial and copy the toolbar item with the cancel button. On lines 23 to 27.
I'll switch to Xcode and paste the code above the add toolbar.
The order of these toolbar items does not matter here. I control where they are positioned via the placement parameter of the toolbar item.
This toolbar item uses the cancellation action placement, which is on the left side of the toolbar. The button uses the Xmark SF Symbol to represent the cancel action.
Now the text cancel is not shown on the toolbar, just like the add button and the button's action sets, the is showing cancel confirmation to true, indicating that a confirmation dialog has to be displayed. I'll switch to the tutorial.
I'll scroll to step seven.
Which adds the confirmation dialog, which avoids people accidentally discarding the information they've entered.
And I'll scroll to step eight, which adds the dismiss action. If the discard button is used, it's good practice to ask for confirmation any time you're about to discard information people have entered. So I'll copy the confirmation dialog code from line 27 to 31.
I'll switch to Xcode and I'll paste it below the cancel button.
The confirmation dialog has Discard Moment as its title. It binds to the is showing cancel confirmation variable to determine if it should be presented when it is presented. The button is shown in the confirmation dialog.
It has discard moment as its message and destructive as its role, and if it's used, the dismiss function is called. Okay, that's taken care of. I'll switch to the tutorial. I'll scroll to step nine, which adds the last data validation I need. So here on line 25, if the title, the note and the image are empty, there is no risk of data loss. This means that I can dismiss my view Immediately without showing the confirmation dialog.
Otherwise, if information was already entered, I would need to show the dialog.
I'll copy the code from lines 25 to line 27, and I'll switch to Xcode.
I'll paste it right above where I set is showing cancel confirmation equals to true.
And right after it I'll add my closing braces.
Great. I can now test some of this functionality in the SwiftUI preview. I'll type in the letter A in the note and I'll click on the cancel button. The confirmation dialog appears as expected since the note has a letter A. Now, if I remove the A and click on cancel again, the confirmation dialog does not show up as expected. Did.
Okay, now I have a cancel button which prevents data loss by showing an alert when needed. And my app is now really functional. The information captured by my views is connected to SwiftData for persistence. The toolbar now has familiar buttons people can use to manage their entry, and people can only save entries once they've provided enough information.
And this is as far as this tutorial goes. I've completed all the steps in every section, but now I want to add a final touch. A bonus for you that is not in this tutorial.
I want to show you the moment entry view being presented and dismissed in the simulator. I'll present it as a sheet from the content view, so I'll switch to Xcode.
I'll go to the Content view file.
And at the top I'll declare a variable to control the display of my sheet.
It's a state private var called is presented of type bool. Set to false. So at state private var is presented equals to false.
Then I'll delete what's in the VStack and add a button.
I'll select the title key action initializer and hit return to accept it.
I'll type in create a Grateful Moment. I'll hit Tab and return to create the actions. Closure where I'll set is presented Entered equals to true.
Finally, I'll style the button with button style bordered to give it some visual importance.
Next I'll add a sheet modifier.
I'll type sheet and hit escape and select the Ispresented content initializer and hit return.
I'll bind the Ispresented variable to it, hit tab and return to create the content closure where I'll type in moment and review.
And that's it. I'll use command R to run the app in the simulator, and once it's loaded, I'll click on the create a Grateful Moments button And the sheet is presented. Now I'll demonstrate how useful this is.
At the top, I'll enter the title. I'm grateful for completing the tutorial and in my small wins I'll say I learned how to add a photo.
I'll tap the button to launch the photo picker and select the waterfall. This is awesome! This interface makes it easy to log Grateful Moments. I'll switch to the tutorial to highlight one more thing.
I'll scroll down to the Check your Understanding section where you can test your knowledge. I'll leave this as an exercise for you to do at home. A bit further down you can move on to the next tutorial called Use a custom layout view and keep building the Grateful Moments demo app. In that tutorial, you'll actually display the entries created in the moments entry view in a list using a very cool custom hexagon layout showing each entry's details.
Now, before I let you go, here are some next steps.
Take the Grateful Moments app to the next level and complete the remaining tutorials. You'll visualize the entries people create and add features like badges and streak indicators, visualizing how often people log their Grateful Moments.
Customize the app with your own ideas. Change values and arguments to turn the Grateful Moments app into other types of habit tracking apps. For example, an app that tracks studying, exercising, or any other lifestyle change. Finally, check out the Apple Developer documentation. There are many resources available at Developer.apple.com, including sample projects, videos and articles. These are great ways to build the skills to design and develop for Apple platforms. Thanks for joining me. Keep on learning and building apps.
Wow, that was awesome. Thank you Lucas. Oh, it's so cool to have a familiar face from the code-along.
And wow, I know that that was a lot to take in. If you want to revisit this code-along later or share it with a friend, I have really great news. This recording will be available soon on the Apple Developer App website and on YouTube.
Now Lucas you and your team have created all of the tutorials. I've got to ask, what was the biggest highlight of creating that material? Well, I think one of the highlights was just to see the attention and the care for every detail that went into it. Each step, each preview, each line of code, it was really thought through. Always with the learner in mind. Yeah, make learning easier. I really appreciate how, like, there's so much progress that could be made at every step. It feels intentional. And for each tour you you have a as a learner, you have an understanding of what skills you learn and the confidence that it'll take you through every step.
So and just the exposure to new frameworks like it kind of removes that barrier to entry. So I think it's a great resource now not to put you on the spot, but do you have a favorite tutorial? You mentioned in the code-along that there are seven. Yeah. Which one? Which one really stands out to you or was the most fun to make? I think this one that we just saw was my favorite one, because it gathers everything you learn from app design, SwiftUI and data modeling. And start applying it to a new app where which is developed fully in the tutorial. So I think this one is a great place. It's one of my favorite ones. It has a strong base. It exposes you to SwiftData, so it ties everything that you've learned so far in the tutorials into a good starting point. Yeah, I love how the principles of, you know, getting like getting into SwiftUI, getting into Xcode for the first time, using SwiftData to store information from your app and and get it back the next time you open the app. I feel like these are all really valuable fundamentals that can be applied, whether you're just customizing Grateful Moments to do something else that you want to do, like make a fitness tracking app, or if you want to say, okay, I have this brand new idea, how do I get started? Okay, I know I can use SwiftUI to make the views in my app like it. It's really just getting the wheels turning on. On building an app from scratch, which I think is is so valuable now. We received a lot of great questions during the code-along. But first, I want to dive deeper into something that we mentioned earlier. So Lucas, what is the Swift Student Challenge? The Swift Student Challenge is a great opportunity for students around the world to be recognized by their for their ideas, their creativity, their technical skills. So if you're a student, build an app on any topic of your choice and participate in the Swift Student Challenge 2026. So you mentioned some important dates earlier. Tell me more about that. When can students submit their app? So submissions are open from February 6th through the 28th. And make sure to visit the Swift Student Challenge webpage to learn more about eligibility. And you can also join us on January 15th for another Meet with Apple event to get you ready for the Swift Student Challenge. So now is a great time to start preparing that. That is super cool. And what I really appreciate is that there's a solid amount of time until it's time to submit an app for the Swift Student Challenge. So today it's okay if you don't have prior app development experience. Today, you can start learning now. You just learned with Lucas some of the basics for setting up an app and taking the idea of Grateful Moments, putting it into code, trying it in SwiftUI previews, trying it in the simulator, taking an idea and iterating on it. And there are other tutorials to take you along the way as well, so I. I am really excited. There's all this time to get ready for the Swift Student Challenge. There's that time in January. And I'm really inspired by many of the students I've met through the Swift Student Challenge and their ideas, and even people who don't have traditional coding experience, they're able to take these ideas they're really passionate about and then translate that into an app that solves important problems in their lives and in their communities. So take some time and think to you about think to yourself, what question, what problem do I want to solve? What am I really excited about? And and how can I leverage SwiftUI and and building an app to solve that problem and bring awareness to it too? So Lucas for people who are brand new to app development, where do you recommend they get started? So I would say learn by doing so. Get your idea into paper, turn it into a wireframe, into a prototype, show it around, test it, refine it, and then you can start building the app.
Also check out obviously the Develop in Swift Tutorials a great place to start, and the Apple developer documentation where you can download sample code. Watch WWDC videos. Try out new frameworks. Also explore the coding intelligence tools in Xcode 26 that will help you learn, write code, fix errors, and much more. And speaking of which, on February 5th joined the meet with Apple Code-along session where you can follow along and experiment with the latest coding intelligence tools in Xcode 26. Yeah, that that is that is so cool. I love that, I love all the resources you highlight that there's not. The tutorials are really great way to get started and you can build Grateful Moments if you're interested in other topics like spatial computing or machine learning, there's a a well-vetted path to building some experience there. But there are also these other tools like the WWDC videos and and written documentation on the Apple Developer website that really help help you explore other frameworks and technologies and and get ideas of how to use them in apps. There's a lot of sample apps on the website, so to those who are new to Apple platforms or even more experienced and looking to expand your exposure, the Developer.apple.com website is super helpful for increasing your exposure and then getting ideas to use those frameworks in your own apps and build something new.
So Lucas after building an app like Grateful Moments, what's the next step? How do you test it to make sure it's behaving as you would hope or expect? Yeah. So testing is one of the most important features or, you know, things you should do when you're testing developing an app, both on the app design phase where you're trying to figure out how your idea is going to be become an app. So testing that phase, but also test after you build the app to make sure that things are behaving correctly. You have no bugs and you can learn all about this in the app distribution tutorials. There you'll learn about TestFlight, which is a great tool to share and get feedback that. I love how the tutorials take everything from idea to execution to validation and sharing your ideas, because that's where apps have significant impact. It's so cool that those resources are there. Very cool. Okay, awesome. So now I want to move to some questions that were asked during the code-along. And by the way, this is really exciting. We have people joining us from over 100 countries. So thank you. Thank you for joining and thank you for your questions. So we're going to start off with one from Joe. Why in the tutorial why separate out the content stack into a variable rather than develop inline with the body. Is there an advantage to that? Well, the main advantage would be for code readability to keep things separate and structured. And it's always good practice to have smaller views so that you can manage them more efficiently and more clearly. And also there's some, you know, performance considerations if you have a very, very large view and you have one, you know, in the body, you have ten different parameters that are going to be that your view depends on and you just change one of them, SwiftUI will regenerate the entire view. If you have them separate, only that little chunk of the view will be updated. In our case, it's such a small view that performance might not be a consideration, but if you have a larger view with many variables, that could start affecting performance. Yeah, you touched on two really interesting things in the in the coding tutorial or in the code-along. You said that it was a preference for readability to put the to pull the content in the content stack out. So you could put it in the scroll view. And I think what's really cool is there's so many ways to do the same thing. You could have taken everything in the content stack and put it in in its own view. You could have put it in a new file and so or you could have just taken everything in the content view and put it straight up into into body. And so I think that's really neat. There's always, you know, like in coding in general there's multiple ways to do the same thing. There's trade offs Advantages. Readability is always a factor.
But what I really want to underscore is the importance of structuring your views intentionally and SwiftUI. A great principle you can take with you in general is each view should have, should really just like should really just depend on the information that's important to that view. And that will make your code easier to reason about. You can look at what's changing and how it is affecting the the layout of your view and its behavior. It's really great for performance, which is which is, you know, maybe more of an advanced topic once you have built some experience building apps and you can start to reason about the way to to build views intentionally. But it's it's always good to start thinking about how to structure your code effectively and efficiently, both so that it's readable, easy to reason about, and you can rely on the efficient performance of your app, especially as it grows and you keep adding new functionality and new views. So that is really cool. And we had actually an event in the Developer Center last week geared on performance. So if that's something you're interested in, there's a recording of that available. And I really encourage you to take the time to think about how to structure your views in SwiftUI efficiently. It's a great it's a great thing to have on your roadmap of a tool you'll take with you into the future as you keep building apps. So now I want to surface a question from Gina. What is UIImage? So the UIImage is a way to show a photo on your app. It's a representation of the the photo image data that you can show using UIKit. Yeah. And something that's really interesting is anytime there's something that I see, maybe in some sample code and I don't know what it is, how how do you like how do you figure out what it is, what techniques do you use. So you can you know, just place your cursor on that variable or that modifier or whatever you want to learn more about. Use command option three to show up the to to open up the quick help. And then within the quick help, you can also click through and open the actual documentation for that that object and read more about it. There you'll find sample code, the properties, the different parameters.
Also in in some cases it will link you to the human interface guidelines that will show you when to use a UI element, where to use it, and how it's more commonly used so that your UI is very familiar for the user. That's great. I, I love referencing the documentation on the developer website and in Xcode, because I feel like I'm empowered to answer my own questions. And it's a muscle you build over time, getting to use the tool efficiently and become familiar with it, but I think it really unlocks a lot of learning efficiently. So thank you for your question. So now I have a question from David. Could you please explain a little bit of guard inlet variables, which I noticed from the code-along? Yeah. Tell me more about guard let. So Bartlett is does the same thing as an if statement where you're verifying if that variable has a value or is still in the guard. Let it will guard yourself from a nil object. So if a guard let succeeds it will continue the code. Otherwise there's an else block that you can return, get out of that function or treat that error. So you know again it's one of many ways of doing the same thing. Yeah, yeah. Learning learning syntaxes I feel like a another really great experience of doing things like the code-along where you see some code and you're, you're trying to you're reading the code and you're trying to reason about it and understand the behavior. And a big thing in Swift, like many languages, is that there's multiple ways to do the same thing. And I love to in your code-along how you explained flatMap and had the side by side comparison of, you know, o flatMap is unfamiliar. Check out this longer way that does the same logic and just learning the syntax of flatMap and throwing. I love throwing the documentation. The Swift language documentation has a lot of really great examples for learning. Learning the syntax of Swift so that both. Maybe you could try some new syntax in your code to make it more like more readable and verbose, but also to understand syntax that other people are using. So I really it's really a great documentation. There's good examples. So another great learning resource.
Okay, so we have time for one more question. And I'm really excited about this one. This one's from Ayush. What is one design principle that beginners should adopt early to make their apps feel truly Apple like. It seems like an obvious response, but use the system UI elements follow the Human Interface guidelines, which will show you what elements to use where. So you wouldn't want to put a cancel button on the bottom left, you want to put on the top left and use the toolbar. Use lists and the segment the pickers that are provided to you in the system framework. There's tried and tested, and they're very familiar to every everyone who's using apps for the Apple platforms. I, I love the sentiment of we keep saying resources, resources, resources. We're like, go check out Developer.apple.com. You mentioned the human interface guidelines. Those are guidelines developed by developed in tandem by designers and engineers at Apple who have put a lot of thought into making apps Consistent, easy to use, intuitive, and accessible so that you can leverage these really well thought out design techniques and incorporate them into your app so that people will start using your app and know how to use it. So I love that sentiment of using standard system controls in SwiftUI things like buttons, tab bars, using. Those are both a great way to quickly, with a few lines of code, add functionality to your app, like in the Code-along using the toolbar items so quickly building out an app that's functional and intuitive, but is also accessible and really provides value to people who use your app. So lean into those and they'll really empower you on your app journey. Both the human interface guidelines for learning about the theory of design and the intentionality behind it, and then leveraging the system frameworks for all of their greatness. Well, Lucas, thank you and thank you so much for taking the time to join us. If we didn't get the chance to answer your question, I encourage you to check out the developer forums at developer Quad LED True Tone flash.
It is a great place to ask questions and to learn from others.
Yes, thank you for joining us, and be sure to check out all of our learning resources on Developer.apple.com.
And if you're a student, check out the Swift Student Challenge 2026 and you can submit your projects starting on February 6th.
Thank you so much for letting us be a part of your journey as a developer. I hope you leave today learning something new and that you'll join us again soon, whether online or at a developer center near you.
-