Skip to content

Commit 313f5a2

Browse files
committed
Everything compiles
1 parent 266c374 commit 313f5a2

18 files changed

+563
-540
lines changed

.github/workflows/swift.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: styfle/[email protected]
1414
with:
1515
workflow_id: ${{ github.event.workflow.id }}
16-
16+
1717
build_and_test_spm_mac:
1818
needs: cancel_previous
1919
runs-on: macos-latest
@@ -46,6 +46,23 @@ jobs:
4646
- name: Run tests
4747
run: swift test --enable-test-discovery
4848

49+
build_and_test_spm_windows:
50+
needs: cancel_previous
51+
runs-on: windows-latest
52+
steps:
53+
- uses: compnerd/gha-setup-swift@main
54+
with:
55+
branch: swift-5.8-release
56+
tag: 5.8-RELEASE
57+
- uses: actions/checkout@v2
58+
- uses: webfactory/[email protected]
59+
with:
60+
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
61+
- name: Build
62+
run: swift build
63+
- name: Run tests
64+
run: swift test --enable-test-discovery
65+
4966
build_and_test_ios:
5067
needs: cancel_previous
5168
runs-on: macos-latest
@@ -85,7 +102,7 @@ jobs:
85102
with:
86103
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
87104
- run: xcodebuild -scheme Segment test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
88-
105+
89106
build_and_test_examples:
90107
needs: cancel_previous
91108
runs-on: macos-latest
@@ -117,4 +134,3 @@ jobs:
117134
run: |
118135
cd Examples/apps/SegmentUIKitExample
119136
xcodebuild -workspace "SegmentUIKitExample.xcworkspace" -scheme "SegmentUIKitExample" -destination 'platform=macOS,variant=Mac Catalyst'
120-

Examples/other_plugins/NotificationTracking.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333

3434
// MARK: Common
3535

36-
#if !os(Linux) && !os(macOS)
36+
#if !os(Linux) && !os(macOS) && !os(Windows)
3737

3838
import Foundation
3939
import Segment
4040

4141
class NotificationTracking: Plugin {
4242
var type: PluginType = .utility
4343
weak var analytics: Analytics?
44-
44+
4545
func trackNotification(_ properties: [String: Codable], fromLaunch launch: Bool) {
4646
if launch {
4747
analytics?.track(name: "Push Notification Tapped", properties: properties)
@@ -95,4 +95,3 @@ extension NotificationTracking: iOSLifecycle {
9595
}
9696

9797
#endif
98-

Sources/Segment/Analytics.swift

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public class Analytics {
2020
}
2121
internal var store: Store
2222
internal var storage: Storage
23-
23+
2424
/// Enabled/disables debug logging to trace your data going through the SDK.
2525
public static var debugLogsEnabled = false
26-
26+
2727
public var timeline: Timeline
28-
28+
2929
static internal let deadInstance = "DEADINSTANCE"
3030
static internal weak var firstInstance: Analytics? = nil
31-
31+
3232
/**
3333
This method isn't a traditional singleton implementation. It's provided here
3434
to ease migration from analytics-ios to analytics-swift. Rather than return a
3535
singleton, it returns the first instance of Analytics created, OR an instance
3636
who's writekey is "DEADINSTANCE".
37-
37+
3838
In the case of a dead instance, an assert will be thrown when in DEBUG builds to
3939
assist developers in knowning that `shared()` is being called too soon.
4040
*/
@@ -44,53 +44,53 @@ public class Analytics {
4444
return a
4545
}
4646
}
47-
47+
4848
#if DEBUG
4949
if isUnitTesting == false {
5050
assert(true == false, "An instance of Analytice does not exist!")
5151
}
5252
#endif
53-
53+
5454
return Analytics(configuration: Configuration(writeKey: deadInstance))
5555
}
56-
56+
5757
/// Initialize this instance of Analytics with a given configuration setup.
5858
/// - Parameters:
5959
/// - configuration: The configuration to use
6060
public init(configuration: Configuration) {
6161
store = Store()
6262
storage = Storage(store: self.store, writeKey: configuration.values.writeKey)
6363
timeline = Timeline()
64-
64+
6565
// provide our default state
6666
store.provide(state: System.defaultState(configuration: configuration, from: storage))
6767
store.provide(state: UserInfo.defaultState(from: storage))
68-
68+
6969
storage.analytics = self
70-
70+
7171
checkSharedInstance()
72-
72+
7373
// Get everything running
7474
platformStartup()
7575
}
76-
76+
7777
internal func process<E: RawEvent>(incomingEvent: E) {
7878
guard enabled == true else { return }
7979
let event = incomingEvent.applyRawEventData(store: store)
80-
80+
8181
_ = timeline.process(incomingEvent: event)
82-
82+
8383
let flushPolicies = configuration.values.flushPolicies
8484
for policy in flushPolicies {
8585
policy.updateState(event: event)
86-
86+
8787
if (policy.shouldFlush() == true) {
8888
flush()
8989
policy.reset()
9090
}
9191
}
9292
}
93-
93+
9494
/// Process a raw event through the system. Useful when one needs to queue and replay events at a later time.
9595
/// - Parameters:
9696
/// - event: An event conforming to RawEvent that will be processed.
@@ -129,28 +129,28 @@ extension Analytics {
129129
store.dispatch(action: System.ToggleEnabledAction(enabled: value))
130130
}
131131
}
132-
132+
133133
/// Returns the anonymousId currently in use.
134134
public var anonymousId: String {
135135
if let userInfo: UserInfo = store.currentState() {
136136
return userInfo.anonymousId
137137
}
138138
return ""
139139
}
140-
140+
141141
/// Returns the userId that was specified in the last identify call.
142142
public var userId: String? {
143143
if let userInfo: UserInfo = store.currentState() {
144144
return userInfo.userId
145145
}
146146
return nil
147147
}
148-
148+
149149
/// Returns the current operating mode this instance was given.
150150
public var operatingMode: OperatingMode {
151151
return configuration.values.operatingMode
152152
}
153-
153+
154154
/// Adjusts the flush interval post configuration.
155155
public var flushInterval: TimeInterval {
156156
get {
@@ -163,7 +163,7 @@ extension Analytics {
163163
}
164164
}
165165
}
166-
166+
167167
/// Adjusts the flush-at count post configuration.
168168
public var flushAt: Int {
169169
get {
@@ -176,41 +176,41 @@ extension Analytics {
176176
}
177177
}
178178
}
179-
179+
180180
/// Returns a list of currently active flush policies.
181181
public var flushPolicies: [FlushPolicy] {
182182
get {
183183
configuration.values.flushPolicies
184184
}
185185
}
186-
186+
187187
/// Returns the traits that were specified in the last identify call.
188188
public func traits<T: Codable>() -> T? {
189189
if let userInfo: UserInfo = store.currentState() {
190190
return userInfo.traits?.codableValue()
191191
}
192192
return nil
193193
}
194-
194+
195195
/// Returns the traits that were specified in the last identify call, as a dictionary.
196196
public func traits() -> [String: Any]? {
197197
if let userInfo: UserInfo = store.currentState() {
198198
return userInfo.traits?.dictionaryValue
199199
}
200200
return nil
201201
}
202-
202+
203203
/// Tells this instance of Analytics to flush any queued events up to Segment.com. This command will also
204204
/// be sent to each plugin present in the system. A completion handler can be optionally given and will be
205205
/// called when flush has completed.
206206
public func flush(completion: (() -> Void)? = nil) {
207207
// only flush if we're enabled.
208208
guard enabled == true else { return }
209-
209+
210210
let flushGroup = DispatchGroup()
211211
// gotta call enter at least once before we ask to be notified.
212212
flushGroup.enter()
213-
213+
214214
apply { plugin in
215215
// we want to enter as soon as possible. waiting to do it from
216216
// another queue just takes too long.
@@ -228,9 +228,9 @@ extension Analytics {
228228
}
229229
}
230230
}
231-
231+
232232
flushGroup.leave() // matches our initial enter().
233-
233+
234234
// if we ARE in sync mode, we need to wait on the group.
235235
// This effectively ends up being a `sync` operation.
236236
if operatingMode == .synchronous {
@@ -257,7 +257,7 @@ extension Analytics {
257257
}
258258
}
259259
}
260-
260+
261261
/// Resets this instance of Analytics to a clean slate. Traits, UserID's, anonymousId, etc are all cleared or reset. This
262262
/// command will also be sent to each plugin present in the system.
263263
public func reset() {
@@ -268,13 +268,13 @@ extension Analytics {
268268
}
269269
}
270270
}
271-
271+
272272
/// Retrieve the version of this library in use.
273273
/// - Returns: A string representing the version in "BREAKING.FEATURE.FIX" format.
274274
public func version() -> String {
275275
return Analytics.version()
276276
}
277-
277+
278278
/// Retrieve the version of this library in use.
279279
/// - Returns: A string representing the version in "BREAKING.FEATURE.FIX" format.
280280
public static func version() -> String {
@@ -292,7 +292,7 @@ extension Analytics {
292292
}
293293
return settings
294294
}
295-
295+
296296
/// Manually enable a destination plugin. This is useful when a given DestinationPlugin doesn't have any Segment tie-ins at all.
297297
/// This will allow the destination to be processed in the same way within this library.
298298
/// - Parameters:
@@ -319,15 +319,15 @@ extension Analytics {
319319
return true
320320
}
321321
}
322-
322+
323323
return false
324324
}
325-
325+
326326
/// Provides a list of finished, but unsent events.
327327
public var pendingUploads: [URL]? {
328328
return storage.read(Storage.Constants.events)
329329
}
330-
330+
331331
/// Purge all pending event upload files.
332332
public func purgeStorage() {
333333
if let files = pendingUploads {
@@ -336,12 +336,12 @@ extension Analytics {
336336
}
337337
}
338338
}
339-
339+
340340
/// Purge a single event upload file.
341341
public func purgeStorage(fileURL: URL) {
342342
try? FileManager.default.removeItem(at: fileURL)
343343
}
344-
344+
345345
/// Wait until the Analytics object has completed startup.
346346
/// This method is primarily useful for command line utilities where
347347
/// it's desirable to wait until the system is up and running
@@ -361,7 +361,7 @@ extension Analytics {
361361
Call openURL as needed or when instructed to by either UIApplicationDelegate or UISceneDelegate.
362362
This is necessary to track URL referrers across events. This method will also iterate
363363
any plugins that are watching for openURL events.
364-
364+
365365
Example:
366366
```
367367
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
@@ -376,12 +376,12 @@ extension Analytics {
376376
guard let dict = jsonProperties.dictionaryValue else { return }
377377
openURL(url, options: dict)
378378
}
379-
379+
380380
/**
381381
Call openURL as needed or when instructed to by either UIApplicationDelegate or UISceneDelegate.
382382
This is necessary to track URL referrers across events. This method will also iterate
383383
any plugins that are watching for openURL events.
384-
384+
385385
Example:
386386
```
387387
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
@@ -392,14 +392,14 @@ extension Analytics {
392392
*/
393393
public func openURL(_ url: URL, options: [String: Any] = [:]) {
394394
store.dispatch(action: UserInfo.SetReferrerAction(url: url))
395-
395+
396396
// let any conforming plugins know
397397
apply { plugin in
398398
if let p = plugin as? OpeningURLs {
399399
p.openURL(url, options: options)
400400
}
401401
}
402-
402+
403403
var jsonProperties: JSON? = nil
404404
if let json = try? JSON(options) {
405405
jsonProperties = json
@@ -428,7 +428,7 @@ extension Analytics {
428428
Self.firstInstance = self
429429
}
430430
}
431-
431+
432432
/// Determines if an instance is dead.
433433
internal var isDead: Bool {
434434
return configuration.values.writeKey == Self.deadInstance
@@ -453,4 +453,3 @@ extension OperatingMode {
453453
}
454454
}
455455
}
456-

0 commit comments

Comments
 (0)