Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix strong concurrency warnings #128

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PostHog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
Expand Down Expand Up @@ -1287,6 +1288,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
Expand Down Expand Up @@ -1354,6 +1356,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1415,6 +1418,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1458,6 +1462,7 @@
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 13.0;
Expand Down Expand Up @@ -1500,6 +1505,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 13.0;
Expand Down
2 changes: 1 addition & 1 deletion PostHog/Models/PostHogEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public class PostHogEvent {
public class PostHogEvent: @unchecked Sendable {
public var event: String
public var distinctId: String
public var properties: [String: Any]
Expand Down
8 changes: 4 additions & 4 deletions PostHog/PostHogApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class PostHogApi {
class PostHogApi: @unchecked Sendable {
private let config: PostHogConfig

// default is 60s but we do 10s
Expand Down Expand Up @@ -35,7 +35,7 @@ class PostHogApi {
return request
}

func batch(events: [PostHogEvent], completion: @escaping (PostHogBatchUploadInfo) -> Void) {
func batch(events: [PostHogEvent], completion: @escaping @Sendable (PostHogBatchUploadInfo) -> Void) {
guard let url = URL(string: "batch", relativeTo: config.host) else {
hedgeLog("Malformed batch URL error.")
return completion(PostHogBatchUploadInfo(statusCode: nil, error: nil))
Expand Down Expand Up @@ -92,7 +92,7 @@ class PostHogApi {
}.resume()
}

func snapshot(events: [PostHogEvent], completion: @escaping (PostHogBatchUploadInfo) -> Void) {
func snapshot(events: [PostHogEvent], completion: @escaping @Sendable (PostHogBatchUploadInfo) -> Void) {
guard let url = URL(string: config.snapshotEndpoint, relativeTo: config.host) else {
hedgeLog("Malformed snapshot URL error.")
return completion(PostHogBatchUploadInfo(statusCode: nil, error: nil))
Expand Down Expand Up @@ -153,7 +153,7 @@ class PostHogApi {
distinctId: String,
anonymousId: String,
groups: [String: String],
completion: @escaping ([String: Any]?, _ error: Error?) -> Void
completion: @escaping @Sendable ([String: Any]?, _ error: Error?) -> Void
) {
var urlComps = URLComponents()
urlComps.path = "/decide"
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogConsumerPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import Foundation

struct PostHogConsumerPayload {
let events: [PostHogEvent]
let completion: (Bool) -> Void
let completion: @Sendable (Bool) -> Void
}
28 changes: 13 additions & 15 deletions PostHog/PostHogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ import Foundation
import AppKit
#endif

class PostHogContext {
class PostHogContext: @unchecked Sendable {
#if !os(watchOS)
private let reachability: Reachability?
#endif

private lazy var theStaticContext: [String: Any] = {
#if !os(watchOS)
init(_ reachability: Reachability?) {
self.reachability = reachability
}
#else
init() {}
#endif

// UIDevice is marked as @MainActor
@MainActor func staticContext() -> [String: Any] {
// Properties that do not change over the lifecycle of an application
var properties: [String: Any] = [:]

Expand Down Expand Up @@ -80,18 +89,6 @@ class PostHogContext {
#endif

return properties
}()

#if !os(watchOS)
init(_ reachability: Reachability?) {
self.reachability = reachability
}
#else
init() {}
#endif

func staticContext() -> [String: Any] {
theStaticContext
}

private func platform() -> String {
Expand All @@ -102,7 +99,8 @@ class PostHogContext {
return String(cString: machine)
}

func dynamicContext() -> [String: Any] {
// UIScreen is marked as @MainActor
@MainActor func dynamicContext() -> [String: Any] {
var properties: [String: Any] = [:]

#if os(iOS) || os(tvOS)
Expand Down
15 changes: 8 additions & 7 deletions PostHog/PostHogFeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class PostHogFeatureFlags {
class PostHogFeatureFlags: @unchecked Sendable {
private let config: PostHogConfig
private let storage: PostHogStorage
private let api: PostHogApi
Expand Down Expand Up @@ -38,7 +38,7 @@ class PostHogFeatureFlags {
distinctId: String,
anonymousId: String,
groups: [String: String],
callback: @escaping () -> Void
callback: @escaping @Sendable () -> Void
) {
isLoadingLock.withLock {
if self.isLoadingFeatureFlags {
Expand All @@ -52,21 +52,22 @@ class PostHogFeatureFlags {
groups: groups)
{ data, _ in
self.dispatchQueue.async {
guard let featureFlags = data?["featureFlags"] as? [String: Any],
let featureFlagPayloads = data?["featureFlagPayloads"] as? [String: Any]
guard let data = data,
let featureFlags = data["featureFlags"] as? [String: Any],
let featureFlagPayloads = data["featureFlagPayloads"] as? [String: Any]
else {
hedgeLog("Error: Decide response missing correct featureFlags format")

self.notifyAndRelease()

return callback()
}
let errorsWhileComputingFlags = data?["errorsWhileComputingFlags"] as? Bool ?? false
let errorsWhileComputingFlags = data["errorsWhileComputingFlags"] as? Bool ?? false

#if os(iOS)
if let sessionRecording = data?["sessionRecording"] as? Bool {
if let sessionRecording = data["sessionRecording"] as? Bool {
self.config.sessionReplay = self.config.sessionReplay && sessionRecording
} else if let sessionRecording = data?["sessionRecording"] as? [String: Any] {
} else if let sessionRecording = data["sessionRecording"] as? [String: Any] {
// keeps the value from config.sessionReplay since having sessionRecording
// means its enabled on the project settings, but its only enabled
// when local config.sessionReplay is also enabled
Expand Down
4 changes: 2 additions & 2 deletions PostHog/PostHogQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation

*/

class PostHogQueue {
class PostHogQueue: @unchecked Sendable {
enum PostHogApiEndpoint: Int {
case batch
case snapshot
Expand Down Expand Up @@ -221,7 +221,7 @@ class PostHogQueue {
flushIfOverThreshold()
}

private func take(_ count: Int, completion: @escaping (PostHogConsumerPayload) -> Void) {
private func take(_ count: Int, completion: @escaping @Sendable (PostHogConsumerPayload) -> Void) {
dispatchQueue.async {
self.isFlushingLock.withLock {
if self.isFlushing {
Expand Down
Loading
Loading