We will first focus on the AppDelegate, which is the root of the project. It sets shared behaviors and initial actions upon loading. We will add ‘import ICONKit’ to utilize ICONKit. Next, we will add functionality to the application function (we use the argument with the ‘didFinishLaunchingWithOptions’).

The relevant code is below. In this code, we determine if there is a keystore file, named “iconkeystore.” If this exists, then we create a shared object called IconServices.shared (which I’ll describe later). If not, then we create a keystore with the password “iconpassword.” You’ll notice print lines for each of the flow outcomes. Since this tutorial is focused on setup of the environment, we provided these in the code to ensure you can see the execution and learn which path is being taken. In addition, clearly the filename and password should be customized for real-world use.

Now, let us take a look at the IconServices class. This is contained in a separate Swift file, appropriately named IconServices.swift. This class connects to the wallet (via the keystore / password combination), checks the balance of the wallet, and then checks the address. We demonstrate connectivity to the ICON blockchain, through a wallet, with this basic functionality. We will then use these values to show the user the status of their wallet. Notice that you can connect to either the TestNet or the MainNet, based on the value provided to the ICONService object. The code is shown below.