Widgets can display data from your main application, and a main application can display data from a widget. See how data sharing is accomplished in this video.
- [Narrator] Now let's get the data from our app…into our widget.…So we're going to scroll up to the top of my code in…my view controller class, and then I'm going to copy this…line where we define that app group constant,…and I'm going to paste it into today, view controller dot…swift right underneath my import statements.…Now we have this constant to reference our app group.…Now I'm going to create a variable to reference our data.…This is the data that's been loaded from the app group.…Now starting out, we don't have any data, so I'm going…to define it as a variable called data, that is an…array of strings.…
And I'll just initialize it to an array with one empty…string inside of it.…Now our table view, instead of using constant data,…it's going to grab data from this data object.…Now of course, we haven't populated it yet, but we'll…get to that in just a moment.…Let's scroll down, and towards the bottom of the code…here, we have this number of rows in section and cell for…row at method.…So what I'm going to do is change the value returned…
Released
4/6/2017- Understanding the possibilities and limitations of widgets
- Adding a Today extension
- Adjusting widget size
- Connecting UI elements to code
- Creating an app group for sharing data
- Creating custom app URLs
- Sending and receiving URL parameters
- Parsing URL parameters
- Handling URLs
- Going to a specific screen from a widget
Share this video
Embed this video
Video: Display data in a widget