![]() ![]() We can start by creating a new view, Playerview, and this view has one property. But let's start by creating a view that show the current episode. We are going to build this UI step by step. It's the interface for the player when we're going to display the show and episode title, the playback button, and the current time. Here is the UI that we are going to build. We are going to use this example throughout the talk to demonstrate all the tool available to you. And I thought it will be great to build a podcast player with SwiftUI. So I really like listening to a good podcast during my commute to Apple Park. With this principle in mind, take a step back, look at all the source of truth in your code, and then use this information to make decision about the structure of your data. And you can use the tool available in the language to enforcing variant in your data. When you have a single source of truth, you're eliminating inconsistency bug between view and your data. What you shall do instead is lift up the data into a common ancestor and let the two children have a reference to it. And they've made the same mistake many time. Think about all the time you've duplicated the same piece of data, for example, into sibling view and how all the complexity of posting notification, KV observing or responding to a different sequence of event has caused your bug.Īnd it's pretty easy to get wrong. Regardless of where the source of truth live, you should always have a single source of truth.ĭuplicated source of truth can lead to bug and inconsistency because you always have to be careful in keeping them in sync. For example when you have some state about something should be collapsed or not, or it can be external such as when you're displaying a message coming from a persistent model. The source of truth can live in your view hierarchy. The second principle is that every piece of data that you're reading in your view hierarchy has a source of truth. ![]() And that means that you can focus on building the best experience for your user. With SwiftUI, you simply describe the dependency to the framework using few tools and the frameworks handles all the rest. There is no manual synchronization or invalidation. But just like viewing SwiftUI are declarative, data dependency are as well. Every time this value changes, we need to update the view.Īnd so additionally, defining this dependency is a manual process and it can quickly become a complex endeavor. This is a dependency because every time the data changes, your view has to change to reflect the new value.įor example, here in blue I have a view showing some playback control and the view needs to read some data in purple. The first principle is that every time you read a piece of data in your view, you're creating a dependency for that view. But before showing you this tool, I would like to illustrate the two guiding principle that inspired us in designing them. ![]() But if you are not familiar with them, don't worry we're going to explain what they are and when to use them.Īt the end of this talk, you'll know exactly what tool to use and when. You've probably seen some of this tool in previous talk. We have a number of tool at your disposal depending on what you want to achieve. One example is stating your UI like the state of a toggle.ĭata also represent model data, such as the object that drives a list of messages. Data comes in all sort of shapes and form. We will also look under the hood of how SwiftUI updates your view hierarchy to guarantee that you always have a correct and consistent representation of your data.Īnd finally, we will empower you with a mental framework for understanding your data and the tool available to you.īut before moving on, what do we mean by data? Data is all the information that drives your UI. This tool can help you achieve app that are not only beautiful but also well behaved. In this talk, we are going to show you the simple but powerful tool that you have at your disposal to flow data through your view hierarchy. That means that data is a first class citizen in SwiftUI. SwiftUI is the shortest path to a great app, but we also designed it from the ground up with the goal of solving the complexity of UI development. Are you guys excited about SwiftUI? Yeah. My name is Luca Bernardi and I will later be joined by my friend and colleague, Raj Ramamaurthy. Good morning and welcome to Data Flow Through SwiftUI. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |