{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"iOS: Swift Concurrency","type":"basic","slug":"ios-swift-concurrency","excerpt":"How to use the iOS SDK with Swift Concurrency","body":"If you would like to adopt Swift Concurrency in your app, this is possible through the use of our Swift Concurrency wrapper SDK: https://github.com/sailthru/sailthru-mobile-ios-sdk-swift\n\nThe 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.\n\n## Examples\n### SailthruMobile\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// Set Attributes\\nlet attributes = STMAttributes()\\ntry await SailthruMobile().set(attributes: attributes)\\n\\n\\n// Remove Attribute\\ntry await SailthruMobile().removeAttribute(with: \\\"my_attribute\\\")\\n\\n\\n// Clear Device\\ntry await SailthruMobile().clearDeviceData(for: .attributes)\\n\\n\\n// Device ID\\nlet deviceId = try await SailthruMobile().deviceId()\\n\\n\\n// Set User ID\\ntry await SailthruMobile().set(userId: \\\"123456\\\")\\n\\n\\n// Set User Email\\ntry await SailthruMobile().set(userEmail: \\\"123456:::at:::some-site.com\\\")\\n\\n\\n// Recommendations\\nlet recommendations = try await SailthruMobile().recommendations(with: \\\"section-id\\\")\\n\\n\\n// Tracking\\ntry await SailthruMobile().trackPageview(with: URL(string: \\\"some-site.com/page\\\")!, tags: [ \\\"interesting-thing1\\\", \\\"interesting-thing2\\\" ])\\n\\ntry await SailthruMobile().trackImpression(with: \\\"section-id\\\", urls: [ URL(string: \\\"some-site.com/page1\\\")!, URL(string: \\\"some-site.com/page2\\\")!])\\n\\ntry await SailthruMobile().trackClick(with: \\\"section-id\\\", url: URL(string: \\\"some-site.com/page2\\\")!)\\n\\n\\n// Profile Vars\\ntry await SailthruMobile().set(profileVars: [ \\\"varKey\\\": \\\"varVal\\\" ])\\n\\nlet profileVars = try await SailthruMobile().profileVars()\\n\\n\\n// Geo IP\\ntry await SailthruMobile().set(geoIpTrackingEnabled: false)\\n\\n\\n// Purchases\\nlet purchaseItems = [\\n STMPurchaseItem(quantity: 1, title: \\\"thing\\\", price: 2, itemId: \\\"item1\\\", itemUrl: URL(string: \\\"some-site.com/item1\\\")!)!\\n]\\nlet purchase = STMPurchase(purchaseItems: purchaseItems)!\\n\\ntry await SailthruMobile().log(purchase: purchase)\\n\\ntry await SailthruMobile().log(abandonedCart: purchase)\\n\\n// Development\\n#if DEBUG\\ntry await SailthruMobile().setDevelopmentDevice()\\n#endif\\n\",\n \"language\": \"swift\"\n }\n ]\n}\n[/block]\n### STMMessageStream\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// Unread Count\\nlet unreadCount = try await STMMessageStream().unreadCount()\\n\\n\\n// Mark as Read\\nlet message = STMMessage()\\ntry await STMMessageStream().mark(asRead: message)\\n\\ntry await STMMessageStream().mark(asRead: [message])\\n\\n\\n// Message List\\nlet messages = try await STMMessageStream().messages()\\n\\n\\n// Remove Message\\nlet message = STMMessage()\\ntry await STMMessageStream().remove(message: message)\",\n \"language\": \"swift\"\n }\n ]\n}\n[/block]","updates":[],"order":999,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"6261ce15d907bb009d9f68cb","createdAt":"2022-04-21T21:35:17.089Z","user":"5b0b7a46a26e6400036604fd","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"iOS Techniques","slug":"ios-techniques","order":9999,"from_sync":false,"reference":false,"_id":"5e6986ca2c6652006791b6e8","createdAt":"2020-03-12T00:48:10.039Z","version":"5e6156bf5e4a51006dcd818c","project":"55e67aaa9cc7c62b00c4a1ea","__v":0},"version":{"version":"1.5","version_clean":"1.5.0","codename":"ST Rebrand","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5e6156bf5e4a51006dcd8120","5e6156bf5e4a51006dcd8121","5e6156bf5e4a51006dcd8122","5e6156bf5e4a51006dcd8123","5e6156bf5e4a51006dcd8124","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5e6156bf5e4a51006dcd8125","5e6156bf5e4a51006dcd8126","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2","5e69868cbd5dcb006b35867b","5e6986ca2c6652006791b6e8"],"_id":"5e6156bf5e4a51006dcd818c","project":"55e67aaa9cc7c62b00c4a1ea","__v":2,"forked_from":"5b720760c44b7600034b7a08","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z"},"project":"55e67aaa9cc7c62b00c4a1ea","__v":0}
iOS: Swift Concurrency
How to use the iOS SDK with Swift Concurrency