iOS SDK

📦 An SDK to embed Lune enrichment views into your iOS mobile apps

Lune PFM 1
Lune PFM blue
Lune PFM pink

Integration

Add the .xcframework provided to you into your Xcode project by simply dragging it into the Project navigator. With that done, you should be able to import the SDK into any of your Swift files as shown below.

import LuneKit

Initialization

To initialize the SDK, you simply have to create an instance of LuneKitManager that would be used across your app. The constructor accepts optional arguments for global customization of the views in the SDK.

import SwiftUI
import LuneKit

struct HomeView: View {
    @ObservedObject var luneKitManager: LuneKitManager = LuneKitManager(
        primaryColor: "#0055b3" //optional
    )


    var body: some View {
        // removed for simplicity...
    }
}

With the instance in hand, luneKitManager, in this example, you can embed any of the Lune views into your app by calling the method(s) responsible for such views.



We'd look at each view in detail now.

Budget Form

The BudgetForm allows the user to set up a new budget. To use this view, just call the BudgetForm method of your LuneKitManager instance as shown in the example below. The method takes two arguments:

  1. loading: this is an optional argument that indicates the preferred state of the view.
  2. callback: this should be an async method that accepts a Double parameter (amount entered by user), and returns a Bool to show if the request was successful or not. We expect that the method internally makes a request to your backend to set the user's budget.
import SwiftUI
import LuneKit

struct SetBudgetView: View {
    // removed for simplicity...

    func setBudget(Double value) async -> Bool {
        var success: Bool
        // await request to backend
        // set value of success based on response
        return success
    }

    var body: some View {
        luneKitManager.BudgetForm(
            loading: false,
            callback: setBudget
        )
    }
}
Budget form

Budget Summary

The BudgetSummaryView shows the user's overall spend in contrast to his budget and his expected spend per time. To use this view, just call the BudgetSummaryView method of your LuneKitManager instance as shown in the example below. The method takes a BudgetSummary object.

import SwiftUI
import LuneKit

struct BudgetView: View {
    // removed for simplicity...

    var body: some View {
        luneKitManager.BudgetSummaryView(
            summary: <BudgetSummary object>
        )
    }
}
Budget Summary

Category Spend List View

The CategorySpendListView shows the user's spend per each category, the user can modify specified budged for each category. To use this view, just call the CategorySpendListView method of your LuneKitManager instance as shown in the example below. The method takes 4 arguments:

  1. spendPerCategory: a list of CategoryBudgetSpend objects
  2. budget: the user's budget as a Double
  3. errorCallback: this should be a method that accepts a String parameter (messsage). We expect that this method internally uses some sort of feedback mechanism (e.g toasts) to pass message to the user.
  4. saveCallback: this should be an async method that accepts a BudgetUpdate object as parameter, and returns a Bool to show if the request was successful or not. We expect that the method internally makes a request to your backend to update the user's budget, and refresh the budget values too.
import SwiftUI
import LuneKit

struct BudgetView: View {
    // removed for simplicity...

    func warnUser(String message) {
        // display message to user
    }

    func updateBudget(BudgetUpdate data) async -> Bool {
        var success: Bool
        // todo: don't forget to attach the customer_id to your request

        // await request to backend
        // set value of success based on response

        // todo: refresh budget values from backend
        return success
    }

    var body: some View {
        luneKitManager.CategorySpendListView(
            spendPerCategory: [
                // CategoryBudgetSpend objects
            ],
            budget: 9000.00, // budget
            errorCallback: warnUser,
            saveCallback: updateBudget
        )
    }
}
Category Spend List view

Interaction

Editing Budget

Users can interact with the CategorySpendListView when it is in edit mode. In this mode, they get to modify the budget allotted to each spend category manually.

If, at any point, the user tries to allocate more than the overall budget, the errorCallback is triggered with a message about over-allocation.

To allow interaction with the view, call the setEditMode method of your LuneKitManager instance. The method takes an optional Bool argument which determines the interactivity of the view. If the argument is omitted, the method just toggles the interactivity of the view.

luneKitManager.setEditMode(true)

You can also keep track of the value of editMode, if you need it in your app.

Saving Budget

Call the saveBudget method of your LuneKitManager instance to save the user's budget. This disables further interaction by setting editMode to false, and calls saveCallback.

luneKitManager.saveBudget()
Interaction edit

Brand List View

The BrandListView shows a list of brands the user has patronized. To use this view, just call the BrandListView method of your LuneKitManager instance as shown in the example below. The method takes a list of BrandSpend objects.

import SwiftUI
import LuneKit

struct TrendsView: View {
    // removed for simplicity...

    var body: some View {
        luneKitManager.BrandListView(
            brands: [
                // BrandSpend objects...
            ]
        )
    }
}
Brands List view

Transaction List View

The TransactionListView shows a list of enriched transactions in a user-friendly way, which each transaction having an associated brand. To use this view, just call the TransactionListView method of your LuneKitManager instance as shown in the example below.

import SwiftUI
import LuneKit

struct HomeView: View {
    // removed for simplicity...

    var body: some View {
        luneKitManager.TransactionListView(
            transactions: [
                // Transaction objects...
            ]
        )
    }
}
Brands List view

Localization

If your app is already localized, the SDK would be localized as well - no configurations needed. If your app is not localized, however, the SDK respects that and stays in English to preserve consistency and uniformity across your app.

Localization