77
88import Foundation
99import JSONSafeEncoding
10+
1011#if os(Linux) || os(Windows)
11- import FoundationNetworking
12+ import FoundationNetworking
1213#endif
1314
1415// MARK: - Custom AnonymousId generator
@@ -29,7 +30,8 @@ public enum OperatingMode {
2930 /// The operation of the Analytics client are asynchronous.
3031 case asynchronous
3132
32- static internal let defaultQueue = DispatchQueue ( label: " com.segment.operatingModeQueue " , qos: . utility)
33+ static internal let defaultQueue = DispatchQueue (
34+ label: " com.segment.operatingModeQueue " , qos: . utility)
3335}
3436
3537// MARK: - Storage Mode
@@ -47,7 +49,6 @@ public enum StorageMode {
4749
4850// MARK: - Internal Configuration
4951
50- @objc ( SEGTrackedLifecycleEvent)
5152public final class TrackedLifecycleEvent : NSObject , OptionSet {
5253 public let rawValue : Int
5354
@@ -63,44 +64,44 @@ public final class TrackedLifecycleEvent: NSObject, OptionSet {
6364 rawValue. hashValue
6465 }
6566
66- @ objc public static let none : TrackedLifecycleEvent = [ ]
67- @ objc public static let applicationInstalled = TrackedLifecycleEvent ( rawValue: 1 << 0 )
68- @ objc public static let applicationUpdated = TrackedLifecycleEvent ( rawValue: 1 << 1 )
69- @ objc public static let applicationOpened = TrackedLifecycleEvent ( rawValue: 1 << 2 )
70- @ objc public static let applicationBackgrounded = TrackedLifecycleEvent ( rawValue: 1 << 3 )
71- @ objc public static let applicationForegrounded = TrackedLifecycleEvent ( rawValue: 1 << 4 )
67+ public static let none : TrackedLifecycleEvent = [ ]
68+ public static let applicationInstalled = TrackedLifecycleEvent ( rawValue: 1 << 0 )
69+ public static let applicationUpdated = TrackedLifecycleEvent ( rawValue: 1 << 1 )
70+ public static let applicationOpened = TrackedLifecycleEvent ( rawValue: 1 << 2 )
71+ public static let applicationBackgrounded = TrackedLifecycleEvent ( rawValue: 1 << 3 )
72+ public static let applicationForegrounded = TrackedLifecycleEvent ( rawValue: 1 << 4 )
7273 #if os(macOS)
73- @ objc public static let applicationUnhidden = TrackedLifecycleEvent ( rawValue: 1 << 5 )
74- @ objc public static let applicationHidden = TrackedLifecycleEvent ( rawValue: 1 << 6 )
75- @ objc public static let applicationTerminated = TrackedLifecycleEvent ( rawValue: 1 << 7 )
76-
77- @ objc public static let all : TrackedLifecycleEvent = [
78- . applicationInstalled,
79- . applicationUpdated,
80- . applicationOpened,
81- . applicationBackgrounded,
82- . applicationForegrounded,
83- . applicationUnhidden,
84- . applicationHidden,
85- . applicationTerminated,
86- ]
74+ public static let applicationUnhidden = TrackedLifecycleEvent ( rawValue: 1 << 5 )
75+ public static let applicationHidden = TrackedLifecycleEvent ( rawValue: 1 << 6 )
76+ public static let applicationTerminated = TrackedLifecycleEvent ( rawValue: 1 << 7 )
77+
78+ public static let all : TrackedLifecycleEvent = [
79+ . applicationInstalled,
80+ . applicationUpdated,
81+ . applicationOpened,
82+ . applicationBackgrounded,
83+ . applicationForegrounded,
84+ . applicationUnhidden,
85+ . applicationHidden,
86+ . applicationTerminated,
87+ ]
8788 #elseif os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
88- @ objc public static let all : TrackedLifecycleEvent = [
89- . applicationInstalled,
90- . applicationUpdated,
91- . applicationOpened,
92- . applicationBackgrounded,
93- . applicationForegrounded,
94- ]
89+ public static let all : TrackedLifecycleEvent = [
90+ . applicationInstalled,
91+ . applicationUpdated,
92+ . applicationOpened,
93+ . applicationBackgrounded,
94+ . applicationForegrounded,
95+ ]
9596 #elseif os(watchOS)
96- @ objc public static let all : TrackedLifecycleEvent = [
97- . applicationInstalled,
98- . applicationUpdated,
99- . applicationOpened,
100- . applicationBackgrounded,
101- ]
97+ public static let all : TrackedLifecycleEvent = [
98+ . applicationInstalled,
99+ . applicationUpdated,
100+ . applicationOpened,
101+ . applicationBackgrounded,
102+ ]
102103 #else
103- @ objc public static let all = TrackedLifecycleEvent . none
104+ public static let all = TrackedLifecycleEvent . none
104105 #endif
105106}
106107
@@ -121,7 +122,8 @@ public class Configuration {
121122 var operatingMode : OperatingMode = . asynchronous
122123 var flushQueue : DispatchQueue = OperatingMode . defaultQueue
123124 var userAgent : String ? = nil
124- var jsonNonConformingNumberStrategy : JSONSafeEncoder . NonConformingFloatEncodingStrategy = . zero
125+ var jsonNonConformingNumberStrategy : JSONSafeEncoder . NonConformingFloatEncodingStrategy =
126+ . zero
125127 var storageMode : StorageMode = . disk
126128 var anonymousIdGenerator : AnonymousIdGenerator = SegmentAnonymousId ( )
127129 var httpSession : ( ( ) -> any HTTPSession ) = HTTPSessions . urlSession
@@ -145,10 +147,9 @@ public class Configuration {
145147 }
146148}
147149
148-
149150// MARK: - Analytics Configuration
150151
151- public extension Configuration {
152+ extension Configuration {
152153
153154 /// Sets a reference to your application. This can be useful in instances
154155 /// where referring back to your application is necessary, such as within plugins
@@ -157,7 +158,7 @@ public extension Configuration {
157158 /// - Parameter value: A reference to your application.
158159 /// - Returns: The current Configuration.
159160 @discardableResult
160- func application( _ value: Any ? ) -> Configuration {
161+ public func application( _ value: Any ? ) -> Configuration {
161162 values. application = value
162163 return self
163164 }
@@ -167,8 +168,11 @@ public extension Configuration {
167168 /// - Parameter enabled: A bool value
168169 /// - Returns: The current Configuration.
169170 @discardableResult
170- @available ( * , deprecated, message: " Use `setTrackedApplicationLifecycleEvents(_:)` for more granular control " )
171- func trackApplicationLifecycleEvents( _ enabled: Bool ) -> Configuration {
171+ @available (
172+ * , deprecated,
173+ message: " Use `setTrackedApplicationLifecycleEvents(_:)` for more granular control "
174+ )
175+ public func trackApplicationLifecycleEvents( _ enabled: Bool ) -> Configuration {
172176 values. trackedApplicationLifecycleEvents = enabled ? . all : . none
173177 return self
174178 }
@@ -178,7 +182,9 @@ public extension Configuration {
178182 /// - Parameter events: An option set of the events to track.
179183 /// - Returns: The current Configuration.
180184 @discardableResult
181- func setTrackedApplicationLifecycleEvents( _ events: TrackedLifecycleEvent ) -> Configuration {
185+ public func setTrackedApplicationLifecycleEvents( _ events: TrackedLifecycleEvent )
186+ -> Configuration
187+ {
182188 values. trackedApplicationLifecycleEvents = events
183189 return self
184190 }
@@ -189,7 +195,7 @@ public extension Configuration {
189195 /// - Parameter count: Event count to trigger a flush.
190196 /// - Returns: The current Configuration.
191197 @discardableResult
192- func flushAt( _ count: Int ) -> Configuration {
198+ public func flushAt( _ count: Int ) -> Configuration {
193199 values. flushAt = count
194200 return self
195201 }
@@ -200,7 +206,7 @@ public extension Configuration {
200206 /// - Parameter interval: A time interval
201207 /// - Returns: The current Configuration.
202208 @discardableResult
203- func flushInterval( _ interval: TimeInterval ) -> Configuration {
209+ public func flushInterval( _ interval: TimeInterval ) -> Configuration {
204210 values. flushInterval = interval
205211 return self
206212 }
@@ -224,7 +230,7 @@ public extension Configuration {
224230 /// - Parameter settings:
225231 /// - Returns: The current Configuration.
226232 @discardableResult
227- func defaultSettings( _ settings: Settings ? ) -> Configuration {
233+ public func defaultSettings( _ settings: Settings ? ) -> Configuration {
228234 values. defaultSettings = settings
229235 return self
230236 }
@@ -236,7 +242,7 @@ public extension Configuration {
236242 /// - Parameter value: true/false
237243 /// - Returns: The current Configuration.
238244 @discardableResult
239- func autoAddSegmentDestination( _ value: Bool ) -> Configuration {
245+ public func autoAddSegmentDestination( _ value: Bool ) -> Configuration {
240246 values. autoAddSegmentDestination = value
241247 return self
242248 }
@@ -248,7 +254,7 @@ public extension Configuration {
248254 /// - Parameter value: A string representing the desired API host.
249255 /// - Returns: The current Configuration.
250256 @discardableResult
251- func apiHost( _ value: String ) -> Configuration {
257+ public func apiHost( _ value: String ) -> Configuration {
252258 values. apiHost = value
253259 return self
254260 }
@@ -260,7 +266,7 @@ public extension Configuration {
260266 /// - Parameter value: A string representing the desired CDN host.
261267 /// - Returns: The current Configuration.
262268 @discardableResult
263- func cdnHost( _ value: String ) -> Configuration {
269+ public func cdnHost( _ value: String ) -> Configuration {
264270 values. cdnHost = value
265271 return self
266272 }
@@ -271,7 +277,7 @@ public extension Configuration {
271277 /// - Parameter value: A block to call when requests are made.
272278 /// - Returns: The current Configuration.
273279 @discardableResult
274- func requestFactory( _ value: @escaping ( URLRequest ) -> URLRequest ) -> Configuration {
280+ public func requestFactory( _ value: @escaping ( URLRequest ) -> URLRequest ) -> Configuration {
275281 values. requestFactory = value
276282 return self
277283 }
@@ -283,13 +289,13 @@ public extension Configuration {
283289 /// - Parameter value: A block to be called when an error occurs.
284290 /// - Returns: The current Configuration.
285291 @discardableResult
286- func errorHandler( _ value: @escaping ( Error ) -> Void ) -> Configuration {
292+ public func errorHandler( _ value: @escaping ( Error ) -> Void ) -> Configuration {
287293 values. errorHandler = value
288294 return self
289295 }
290296
291297 @discardableResult
292- func flushPolicies( _ policies: [ FlushPolicy ] ) -> Configuration {
298+ public func flushPolicies( _ policies: [ FlushPolicy ] ) -> Configuration {
293299 values. flushPolicies = policies
294300 return self
295301 }
@@ -299,55 +305,59 @@ public extension Configuration {
299305 /// is desired. Use `.client` when operating in a long lived process,
300306 /// desktop/mobile application.
301307 @discardableResult
302- func operatingMode( _ mode: OperatingMode ) -> Configuration {
308+ public func operatingMode( _ mode: OperatingMode ) -> Configuration {
303309 values. operatingMode = mode
304310 return self
305311 }
306312
307313 /// Specify a custom queue to use when performing a flush operation. The default
308314 /// value is a Segment owned background queue.
309315 @discardableResult
310- func flushQueue( _ queue: DispatchQueue ) -> Configuration {
316+ public func flushQueue( _ queue: DispatchQueue ) -> Configuration {
311317 values. flushQueue = queue
312318 return self
313319 }
314320
315321 /// Specify a custom UserAgent string. This bypasses the OS dependent check entirely.
316322 @discardableResult
317- func userAgent( _ userAgent: String ) -> Configuration {
323+ public func userAgent( _ userAgent: String ) -> Configuration {
318324 values. userAgent = userAgent
319325 return self
320326 }
321327
322328 /// This option specifies how NaN/Infinity are handled when encoding JSON.
323329 /// The default is .zero. See JSONSafeEncoder.NonConformingFloatEncodingStrategy for more informatino.
324330 @discardableResult
325- func jsonNonConformingNumberStrategy( _ strategy: JSONSafeEncoder . NonConformingFloatEncodingStrategy ) -> Configuration {
331+ public func jsonNonConformingNumberStrategy(
332+ _ strategy: JSONSafeEncoder . NonConformingFloatEncodingStrategy
333+ ) -> Configuration {
326334 values. jsonNonConformingNumberStrategy = strategy
327335 JSON . jsonNonConformingNumberStrategy = values. jsonNonConformingNumberStrategy
328336 return self
329337 }
330-
338+
331339 /// Specify the storage mode to use. The default is `.disk`.
332340 @discardableResult
333- func storageMode( _ mode: StorageMode ) -> Configuration {
341+ public func storageMode( _ mode: StorageMode ) -> Configuration {
334342 values. storageMode = mode
335343 return self
336344 }
337-
345+
338346 /// Specify a custom anonymousId generator. The default is and instance of `SegmentAnonymousId`.
339347 @discardableResult
340- func anonymousIdGenerator( _ generator: AnonymousIdGenerator ) -> Configuration {
348+ public func anonymousIdGenerator( _ generator: AnonymousIdGenerator ) -> Configuration {
341349 values. anonymousIdGenerator = generator
342350 return self
343351 }
344-
352+
345353 /// Use a custom HTTP session; Useful for non-apple platforms where Swift networking isn't as mature
346354 /// or has issues to work around.
347355 /// - Parameter httpSession: A class conforming to the HTTPSession protocol
348356 /// - Returns: The current configuration
349357 @discardableResult
350- func httpSession( _ httpSession: @escaping @autoclosure ( ) -> any HTTPSession ) -> Configuration {
358+ public func httpSession( _ httpSession: @escaping @autoclosure ( ) -> any HTTPSession )
359+ -> Configuration
360+ {
351361 values. httpSession = httpSession
352362 return self
353363 }
0 commit comments