Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
make swiftlint happier (no more showstoppers)
Browse files Browse the repository at this point in the history
  • Loading branch information
amiantos committed Nov 22, 2018
1 parent 2a481d2 commit 8ce96ae
Show file tree
Hide file tree
Showing 35 changed files with 385 additions and 370 deletions.
3 changes: 0 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
disabled_rules:
- trailing_whitespace
- force_cast
opt_in_rules:
- empty_count
- empty_string
Expand Down
24 changes: 12 additions & 12 deletions Numu Tracker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Development
//let pusher = Pusher(key: "")

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

Fabric.with([Crashlytics.self])

NumuReviewHelper.incrementActivityCount()

let redirectURL: URL = URL(string: "numu://")!
SpotifyLogin.shared.configure(clientID: "SPOTIFY_CLIENT_ID", clientSecret: "SPOTIFY_CLIENT_SECRET", redirectURL: redirectURL)

NotificationCenter.default.addObserver(
self, selector: #selector(self.runLogInOperations), name: .LoggedOut, object: nil)

NotificationCenter.default.addObserver(
self, selector: #selector(self.ckDataChange), name: Notification.Name.CKAccountChanged, object: nil)

runLogInOperations()

return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = SpotifyLogin.shared.applicationOpenURL(url) { (error) in }

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
let handled = SpotifyLogin.shared.applicationOpenURL(url) { (_) in }
return handled
}

@objc func ckDataChange() {
// Need to re-run authorization procedure here.
runLogInOperations()
Expand Down Expand Up @@ -93,14 +93,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

@objc fileprivate func runLogInOperations() {
let queue = OperationQueue()

// Get and store CK record ID if available
let getCKUserOperation = GetCKUserOperation()
// If user account exists already, link it to CK or create new account
let registerWithCKOperation = RegisterWithCKOperation()
// Try to auth with any credentials
let authOperation = AuthOperation()

registerWithCKOperation.addDependency(getCKUserOperation)
authOperation.addDependency(registerWithCKOperation)
authOperation.completionBlock = {
Expand Down
2 changes: 1 addition & 1 deletion Numu Tracker/Classes/Interface/NumuUIButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class NumuUIButton: UIButton {
self.backgroundColor = isHighlighted ? .black : .clear
}
}

}
2 changes: 1 addition & 1 deletion Numu Tracker/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>817</string>
<string>837</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
12 changes: 6 additions & 6 deletions Numu Tracker/Operations/AsyncOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class AsyncOperation: Operation {
enum State: String {
case isReady, isExecuting, isFinished
}

override var isAsynchronous: Bool {
return true
}

var state = State.isReady {
willSet {
willChangeValue(forKey: state.rawValue)
Expand All @@ -27,21 +27,21 @@ class AsyncOperation: Operation {
didChangeValue(forKey: state.rawValue)
}
}

override var isExecuting: Bool {
return state == .isExecuting
}

override var isFinished: Bool {
return state == .isFinished
}

override func start() {
guard !self.isCancelled else {
state = .isFinished
return
}

state = .isExecuting
main()
}
Expand Down
24 changes: 13 additions & 11 deletions Numu Tracker/Operations/Auth/AuthOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
import Crashlytics

class AuthOperation: AsyncOperation {

let queue = OperationQueue()

override func main() {
Expand Down Expand Up @@ -42,24 +42,26 @@ class AuthOperation: AsyncOperation {
self.showLogRegPrompt()
}
}

func sendNotifcations() {
DispatchQueue.main.async(execute: {
NotificationCenter.default.post(name: .LoggedIn, object: self)
NotificationCenter.default.post(name: .UpdatedArtists, object: self)
})
}

func showLogRegPrompt() {
let loginViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(
withIdentifier: "LogRegPrompt") as! UINavigationController
DispatchQueue.main.async {
if let appDelegate = UIApplication.shared.delegate,
let appWindow = appDelegate.window!,
let rootViewController = appWindow.rootViewController {
rootViewController.present(loginViewController, animated: false, completion: nil)
if let loginViewController = UIStoryboard(name: "Main", bundle: Bundle.main)
.instantiateViewController(withIdentifier: "LogRegPrompt") as? UINavigationController {
DispatchQueue.main.async {
if let appDelegate = UIApplication.shared.delegate,
let appWindow = appDelegate.window!,
let rootViewController = appWindow.rootViewController {
rootViewController.present(loginViewController, animated: false, completion: nil)
}
}
} else {
// Display error message?
}
}

}
4 changes: 2 additions & 2 deletions Numu Tracker/Operations/Auth/GetCKUserOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import CloudKit

class GetCKUserOperation: AsyncOperation {

override func main() {
print("Running CKUserRecordIDOperation..")
if UserDefaults.standard.string(forKey: "userRecordID") == nil {
Expand All @@ -28,5 +28,5 @@ class GetCKUserOperation: AsyncOperation {
self.state = .isFinished
}
}

}
12 changes: 6 additions & 6 deletions Numu Tracker/Operations/FetchJSONOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import Foundation
import SwiftyJSON

final class FetchOperation: AsyncOperation {

private(set) var dataFetched: Data?

private let session = URLSession(configuration: .default)
private var dataTask: URLSessionDataTask?
private var url: String
public var json: JSON

init(_ url: String) {
self.url = url
self.json = JSON.null
}

override func main() {

let url = URL(string: self.url)!
dataTask = session.dataTask(with: url) {[unowned self] (data, _, _) in
guard let data = data else { return }

do {
self.json = try JSON(data: data)
} catch {
Expand Down
32 changes: 16 additions & 16 deletions Numu Tracker/Operations/ImportAppleMusicOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import UIKit
import Crashlytics

class ImportAppleMusicOperation: AsyncOperation {

private let session = URLSession(configuration: .default)
private var dataTask: URLSessionDataTask?

var artistsImported: Int = 0

override func main() {
print("Running ImportAppleMusicOperation...")
if !defaults.logged {
self.state = .isFinished
return
}

MPMediaLibrary.requestAuthorization { (status) in
if status == .authorized {
self.runImportArtists()
Expand All @@ -34,7 +34,7 @@ class ImportAppleMusicOperation: AsyncOperation {
}
}
}

func runImportArtists() {
// Build list of artists to be imported.
let query = MPMediaQuery.artists()
Expand All @@ -49,25 +49,25 @@ class ImportAppleMusicOperation: AsyncOperation {
}
let uniques = Array(Set(artistsFound))
let json = ["artists": uniques]

do {
let jsonData = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)

// create post request
let url = URL(string: "https://www.numutracker.com/v2/json.php?import")!
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"

// insert json data to the request
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData

dataTask = session.dataTask(with: request as URLRequest) {[unowned self] (data, _, error) in
guard let data = data else { return }
do {
if let returnedJSON = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
if let success = returnedJSON["success"] {
self.artistsImported = success as! Int
if let success = returnedJSON["success"] as? Int {
self.artistsImported = success
NumuReviewHelper.incrementAndAskForReview()
self.displaySuccessMessage()
DispatchQueue.main.async(execute: {
Expand All @@ -83,16 +83,16 @@ class ImportAppleMusicOperation: AsyncOperation {
print(self.artistsImported)
self.state = .isFinished
}

dataTask?.resume()

} catch {
print(error.localizedDescription)
self.state = .isFinished
}

}

func displaySuccessMessage() {
DispatchQueue.main.async {
let alertView = NumuAlertView()
Expand All @@ -108,7 +108,7 @@ class ImportAppleMusicOperation: AsyncOperation {
}
}
}

func displayAMError() {
var error: String
switch MPMediaLibrary.authorizationStatus() {
Expand Down
Loading

0 comments on commit 8ce96ae

Please sign in to comment.