Skip to content

Commit a0a579c

Browse files
authored
Address all SwiftLint violations (#94)
2 parents 9ec7343 + e832cde commit a0a579c

26 files changed

+220
-221
lines changed

Demo/ParselyDemo/AppDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import ParselyAnalytics
33

44
@UIApplicationMain
55
class AppDelegate: UIResponder, UIApplicationDelegate {
6-
6+
77
// This is unused but necessary in a Storyboard without UISceneDelegate setup.
88
// Without it, the app will show a black screen and log:
99
//
1010
// > The app delegate must implement the window property if it wants to use a main storyboard file.
1111
var window: UIWindow?
1212

1313
var parsely: Parsely!
14-
14+
1515
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1616
self.parsely = Parsely.sharedInstance
1717
self.parsely.configure(siteId: "parsely-configured-default.com")
18-
18+
1919
return true
2020
}
2121
}

Demo/ParselyDemo/FirstViewController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import ParselyAnalytics
44

55
class FirstViewController: UIViewController {
66
let delegate = UIApplication.shared.delegate as! AppDelegate
7-
7+
88
@IBAction func didTouchButton(_ sender: Any) {
99
log("didTouchButton")
1010
let demoMetas = ParselyMetadata(authors: ["Yogi Berr"])
1111
delegate.parsely.trackPageView(url: "http://parsely.com/path/cool-blog-post/1?qsarg=nawp&anotherone=yup", metadata: demoMetas, extraData: ["product-id": "12345"], siteId: "subdomain.parsely-test.com")
1212
}
13-
13+
1414
@IBAction func didStartEngagement(_ sender: Any) {
1515
log("didStartEngagement")
16-
delegate.parsely.startEngagement(url: "http://parsely.com/very-not-real", urlref:"http://parsely.com/not-real", extraData: ["product-id": "12345"], siteId: "engaged.parsely-test.com")
16+
delegate.parsely.startEngagement(url: "http://parsely.com/very-not-real", urlref: "http://parsely.com/not-real", extraData: ["product-id": "12345"], siteId: "engaged.parsely-test.com")
1717
}
18-
18+
1919
@IBAction func didStopEngagement(_ sender: Any) {
2020
log("didStopEngagement")
2121
delegate.parsely.stopEngagement()

Sources/EngagedTime.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import Foundation
22
import os.log
33

44
class EngagedTime: Sampler {
5-
override func sampleFn(key : String) -> Bool {
5+
override func sampleFn(key: String) -> Bool {
66
guard let trackedData = accumulators[key] else {
77
os_log("No accumulator found for key %s. Skipping sampling.", log: OSLog.tracker, type: .debug, key)
88
return false
99
}
1010

1111
return trackedData.isEngaged
1212
}
13-
13+
1414
override func heartbeatFn(data: Accumulator, enableHeartbeats: Bool) {
1515
if enableHeartbeats != true {
1616
return
@@ -32,20 +32,20 @@ class EngagedTime: Sampler {
3232

3333
parselyTracker.track.event(event: event)
3434
}
35-
35+
3636
func startInteraction(url: String, urlref: String = "", extra_data: Dictionary<String, Any>?, idsite: String) {
3737
endInteraction()
3838
os_log("Starting Interaction", log: OSLog.tracker, type: .debug)
3939
let eventArgs = generateEventArgs(url: url, urlref: urlref, extra_data: extra_data, idsite: idsite)
40-
trackKey(key: url, contentDuration: nil, eventArgs: eventArgs, resetOnExisting: true);
40+
trackKey(key: url, contentDuration: nil, eventArgs: eventArgs, resetOnExisting: true)
4141
accumulators[url]!.isEngaged = true
4242
}
43-
43+
4444
func endInteraction() {
4545
os_log("Ending Interaction", log: OSLog.tracker, type: .debug)
4646
for (url, _) in accumulators {
4747
guard var _ = accumulators[url] else {
48-
os_log("No accumulator found for %s, skipping endInteraction", log: OSLog.tracker, type:.debug, url)
48+
os_log("No accumulator found for %s, skipping endInteraction", log: OSLog.tracker, type: .debug, url)
4949
return
5050
}
5151
accumulators[url]!.isEngaged = false

Sources/Event.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Event {
1414
private(set) var last_session_timestamp: UInt64?
1515
private(set) var parsely_site_uuid: String?
1616
let rand: UInt64
17-
17+
1818
init(_ action: String,
1919
url: String,
2020
urlref: String?,
@@ -58,21 +58,21 @@ class Event {
5858
parsely_site_uuid = visitor
5959
}
6060

61-
func toDict() -> Dictionary<String,Any> {
61+
func toDict() -> Dictionary<String, Any> {
6262
var params: Dictionary<String, Any> = [
6363
"url": self.url,
6464
"urlref": self.urlref,
6565
"action": self.action,
6666
"idsite": self.idsite,
6767
]
68-
68+
6969
var data: [String: Any] = extra_data
7070
data["ts"] = self.rand
71-
71+
7272
if let parsely_site_uuid {
7373
data["parsely_site_uuid"] = parsely_site_uuid
7474
}
75-
75+
7676
params["data"] = data
7777

7878
if let metas = self.metadata {

Sources/EventQueue.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ extension Array {
1515

1616
struct EventQueue<T> {
1717
var list = [T]()
18-
19-
mutating func push(_ element:T) {
18+
19+
mutating func push(_ element: T) {
2020
os_log("Event pushed into queue", log: OSLog.tracker, type: .debug)
2121
list.append(element)
2222
}
2323

24-
mutating func push<Collection>(contentsOf elements:Collection) where T == Collection.Element, Collection: Sequence {
24+
mutating func push<Collection>(contentsOf elements: Collection) where T == Collection.Element, Collection: Sequence {
2525
os_log("Events pushed into queue", log: OSLog.tracker, type: .debug)
2626
list.append(contentsOf: elements)
2727
}
28-
28+
2929
mutating func pop() -> T? {
3030
if list.isEmpty {
3131
return nil
3232
}
3333
os_log("Event popped from queue", log: OSLog.tracker, type: .debug)
3434
return list.removeFirst()
3535
}
36-
37-
mutating func get(count:Int = 0) -> [T] {
36+
37+
mutating func get(count: Int = 0) -> [T] {
3838
if count == 0 {
3939
os_log("Got %zd events from queue", log: OSLog.tracker, type: .debug, list.count)
4040
return list.take(list.count)
4141
}
4242
os_log("Got %zd events from queue", log: OSLog.tracker, type: .debug, count)
4343
return list.take(count)
4444
}
45-
45+
4646
func length() -> Int {
4747
return list.count
4848
}

Sources/HttpClient.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import os.log
44
class HttpClient {
55
static func sendRequest(request: ParselyRequest, queue: DispatchQueue, completion: ((Error?) -> Void)? = nil) {
66
os_log("Sending request to %s", log: OSLog.tracker, type: .debug, request.url)
7-
7+
88
guard let url = URL(string: request.url) else {
99
os_log("Failed to create URL from %s", log: OSLog.tracker, type: .error, request.url)
1010
return
1111
}
12-
12+
1313
var urlRequest = URLRequest(url: url)
1414
urlRequest.httpMethod = "POST"
1515
urlRequest.httpBody = try? JSONSerialization.data(withJSONObject: request.params)
1616
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
17-
17+
1818
request.headers.forEach { key, value in
1919
urlRequest.setValue(value, forHTTPHeaderField: key)
2020
}
21-
21+
2222
URLSession.shared.dataTask(with: urlRequest) { _, _, error in
2323
if let err = error {
2424
os_log("Request failed: %s", log: OSLog.tracker, type: .error, err.localizedDescription)

Sources/Metadata.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public class ParselyMetadata {
99
var section: String?
1010
var tags: Array<String>?
1111
var duration: TimeInterval?
12-
12+
1313
/**
1414
A class to manage and re-use metadata. Metadata contained in an instance of this
1515
class will conform to Parsely's schema.
16-
16+
1717
- Parameter canonical_url: A post's canonical url. For videos, it is overridden with the vId and thus can be omitted.
1818
- Parameter pub_date: Date this piece of content was published.
1919
- Parameter title: Title of the content.
@@ -22,15 +22,15 @@ public class ParselyMetadata {
2222
- Parameter section: Same as section for website integration.
2323
- Parameter tags: Up to 20 tags on an event are allowed.
2424
- Parameter duration: Durations passed explicitly to trackVideoStart take precedence over any in metadata.
25-
*/
25+
*/
2626
public init(canonical_url: String? = nil,
27-
pub_date: Date? = nil,
28-
title: String? = nil,
29-
authors: Array<String>? = nil,
30-
image_url: String? = nil,
31-
section: String? = nil,
32-
tags: Array<String>? = nil,
33-
duration: TimeInterval? = nil) {
27+
pub_date: Date? = nil,
28+
title: String? = nil,
29+
authors: Array<String>? = nil,
30+
image_url: String? = nil,
31+
section: String? = nil,
32+
tags: Array<String>? = nil,
33+
duration: TimeInterval? = nil) {
3434
self.canonical_url = canonical_url
3535
self.pub_date = pub_date
3636
self.title = title
@@ -40,15 +40,15 @@ public class ParselyMetadata {
4040
self.tags = tags
4141
self.duration = duration
4242
}
43-
43+
4444
func toDict() -> Dictionary<String, Any> {
4545
var metas: Dictionary<String, Any> = [:]
46-
46+
4747
if let canonical_url {
4848
metas["link"] = canonical_url
4949
}
5050
if let pub_date {
51-
metas["pub_date"] = String(format:"%i", pub_date.millisecondsSince1970)
51+
metas["pub_date"] = String(format: "%i", pub_date.millisecondsSince1970)
5252
}
5353
if let title {
5454
metas["title"] = title
@@ -68,7 +68,7 @@ public class ParselyMetadata {
6868
if let duration {
6969
metas["duration"] = duration
7070
}
71-
71+
7272
return metas
7373
}
7474
}

0 commit comments

Comments
 (0)