SwiftUI App to interact with the Amber Electric API
Amber is an Australian electricity company that retails electricity based on the current, variable wholesale electricity price. The price can be very high, or also very low. So it's useful to be always aware of how much I'm currently paying.
This app currently shows the most-recent, current, and future (forecast) electricity prices, on Watch, iPhone, iPad and Mac (the last two aren't pretty!). Prices are colour-coded based on price, and the current price is highlighted.
Amber have a nice iPhone app. It does the basic job well. But I asked myself, with a nice Public API, and some time on the weekend, could I get a really simple app up and running that did more?
So, to start with, since Amber has a simple and well-described REST API, it seemed like a nice way to explore SwiftUI, after 5+ years of writing no code at all.
As I got started, I discovered that there's not a lot of sample code that describes a basic app that pulls data from a REST API, and populates an interface with that data. I've tried to use basic, current best-practice approaches, based on the various sources around the web, and my own (non-current) experience. I hope this app might help others who are getting started with SwiftUI too.
There's no official Watch app. I wrote a Shortcut to get my current electricity price, but I wanted More. Can I get my Amber prices on my wrist? (Spoiler: yes!)
Wouldn't it be great to have a watch complication so I can know my current price at a glance? Or an iPhone widget? How even do you create these things? This app is my tool to find out. (WIP)
- Create Shared/APIConfig.xcconfig
- Add
APIKey = {YOUR API KEY}
- In the Project file, add this config file as a Configuration.
- Add APIKey = ${APIKey} to the Info file
- Done.
Yeah, I've completely forgotten how to do this. Work it out. Maybe make a PR with instructions?
I haven't written iOS code for over 5 years. I've written very little Swift before at all. I'm happy with what I've done here, but I'm aware there is a ton I don't know. I would be very grateful for any comments, suggestions, or contributions to make it better. It's important to me that this app remains as clear and simple as possible, to get the basic job done.