iOS: Swift Concurrency

How to use the iOS SDK with Swift Concurrency

If you would like to adopt Swift Concurrency in your app, this is possible through the use of our Swift Concurrency wrapper SDK:

The wrapper is available through Swift Package Manager and allows all the iOS SDK asynchronous functionality to be accessed using async/await. Any errors that occur while completing the operations will be thrown and can be caught and handled as appropriate by your app.


Marigold class

// Clear Device
try await Marigold().clearDeviceData(for: .events)

// Device ID
let deviceId = try await Marigold().deviceId()

// Geo IP
try await Marigold().set(geoIpTrackingEnabled: false)

// Development
try await Marigold().setDevelopmentDevice()

EngageBySailthru class

// Set Attributes
let attributes = MARAttributes()
try await EngageBySailthru().set(attributes: attributes)

// Remove Attribute
try await EngageBySailthru().removeAttribute(with: "my_attribute")

// Device ID
let deviceId = try await Marigold().deviceId()

// Set User ID
try await EngageBySailthru().set(userId: "123456")

// Set User Email
try await EngageBySailthru().set(userEmail: "[email protected]")

// Tracking
try await EngageBySailthru().trackPageview(with: URL(string: "")!, tags: [ "interesting-thing1", "interesting-thing2" ])

try await EngageBySailthru().trackImpression(with: "section-id", urls: [ URL(string: "")!, URL(string: "")!])

try await EngageBySailthru().trackClick(with: "section-id", url: URL(string: "")!)

// Profile Vars
try await EngageBySailthru().set(profileVars: [ "varKey": "varVal" ])

let profileVars = try await EngageBySailthru().profileVars()

// Purchases
let purchaseItems = [
  MARPurchaseItem(quantity: 1, title: "thing", price: 2, itemId: "item1", itemUrl: URL(string: "")!)!
let purchase = MARPurchase(purchaseItems: purchaseItems)!

try await EngageBySailthru().log(purchase: purchase)

try await EngageBySailthru().log(abandonedCart: purchase)


// Unread Count
let unreadCount = try await MARMessageStream().unreadCount()

// Mark as Read
let message = MARMessage()
try await MARMessageStream().mark(asRead: message)

try await MARMessageStream().mark(asRead: [message])

// Message List
let messages = try await MARMessageStream().messages()

// Remove Message
let message = MARMessage()
try await MARMessageStream().remove(message: message)