Currently, WatchKit apps are literally extensions to your app. As such, you probably would want to be able to share data between your app and its extensions wouldn’t you? You can do this in several ways, but we are going to go over the simplest way, NSUserDefaults. Now, you might remember my previous post NSUserDefaults — A Swift Introduction already discussed how to use NSUserDefaults. However, that was only for within your app. It is not VERY different, but there are a few new things you have to do to enable this sharing that should be pointed out.
Archives for March 2015
For the last few hundred years, people took their timepieces (pocket or wristwatch) to quickly see the time, and put it right back to their side or into their pocket. They would take a glance and then put it away. With the advent of smart watches, in addition to time, we can have them show whatever we deem fit, so you can look at it for the weather, to know when the next bus is coming, or to see the name of the song playing on your iPhone.
Your phone would have the full Swift app to modify settings about which bus-line your waiting for, and maybe the watch app could let you scroll through the lines available near your location. But when you’re sitting at the bus stop, do you really need to go to all of that rigamarole? At that point, all you’re probably curious is when the next bus for the line you want is coming. You would just glance at it quickly to see something like this right?
That is exactly what Glances on the Apple Watch are for. They give your Swift app the ability to have some quick data available to the user when they swipe up from their home screen. It is more like a today view widget, but without interactivity. It is only there to show the user quick bits of information. If they want more, they can click on the glance to open the Watch App. Unlike notifications though, these don’t pop up to tell the user something, the user looks for them themselves.
With the recent news of the Apple “Spring Forward” announcement on March 9, 2015, it seems appropriate to write a bit more WatchKit material, eh? Well, one of the most common Views in iOS is the UITableView, so why don’t we talk a bit about its little sibling, the WKInterfaceTable. Only time will tell how common this will be in Apple Watch apps, but it will either way be a very useful WKInterface object nonetheless.