Skip to content

Commit f66bca9

Browse files
committed
swiftlint autocorrect
1 parent d31214d commit f66bca9

File tree

9 files changed

+74
-87
lines changed

9 files changed

+74
-87
lines changed

Clients/Ulysses.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class Ulysses: Client {
8585
@param index Optional. The position of the new sheet in its parent group. Use 0 to make it the first sheet. Available since Ulysses 2.8 (API version 2).
8686
*/
8787
public func newSheet(text: String, group: String? = nil, format: String? = nil, index: String? = nil, onSuccess: SuccessCallback? = nil, onFailure: FailureCallback? = nil, onCancel: CancelCallback? = nil) throws {
88-
88+
8989
var parameters = ["text": text]
9090
if let group = group {
9191
parameters["group"] = group
@@ -96,7 +96,7 @@ public class Ulysses: Client {
9696
if let index = index {
9797
parameters["index"] = index
9898
}
99-
99+
100100
try self.perform(action: "new-sheet", parameters: parameters, onSuccess: onSuccess, onFailure: onFailure, onCancel: onCancel)
101101
}
102102

SampleApp/CallbackURLKitDemo/AppDelegate.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1818
let manager = Manager.shared
1919
manager.callbackURLScheme = Manager.urlSchemes?.first
2020
manager[CallbackURLKitDemo.PrintActionString] = CallbackURLKitDemo.PrintAction
21-
21+
2222
return true
2323
}
2424

@@ -27,7 +27,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727
}
2828

2929
}
30-
30+
3131
#elseif os(OSX)
3232
import Cocoa
3333

@@ -39,15 +39,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3939
manager.registerToURLEvent()
4040
manager.callbackURLScheme = Manager.urlSchemes?.first
4141
manager[CallbackURLKitDemo.PrintActionString] = CallbackURLKitDemo.PrintAction
42-
43-
manager["success"] = { (parameters, success, failure, cancel) in
42+
43+
manager["success"] = { (_, success, _, _) in
4444
DispatchQueue.main.async {
4545
success(nil)
4646
}
4747
}
4848

4949
}
50-
50+
5151
}
5252

5353
#endif

SampleApp/CallbackURLKitDemo/CallbackURLKitDemo.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CallbackURLKit
1111

1212
enum DemoError: FailureCallbackError {
1313
case noText
14-
14+
1515
var code: Int {
1616
switch self {
1717
case .noText: return 0
@@ -25,32 +25,32 @@ enum DemoError: FailureCallbackError {
2525
}
2626

2727
open class CallbackURLKitDemo: Client {
28-
28+
2929
public static let instance = CallbackURLKitDemo()
30-
30+
3131
public init() {
3232
super.init(urlScheme: "callbackurlkit")
3333
}
34-
34+
3535
open func printMessage(_ message: String, onSuccess: SuccessCallback? = nil, onFailure: FailureCallback? = nil, onCancel: CancelCallback? = nil) throws {
3636
let parameters = ["text": message]
3737
try self.perform(action: CallbackURLKitDemo.PrintActionString, parameters: parameters,
3838
onSuccess: onSuccess, onFailure: onFailure, onCancel: onCancel)
3939
}
40-
40+
4141
public static let PrintActionString = "print"
42-
public static let PrintAction: ActionHandler = { parameters, success, failed, cancel in
42+
public static let PrintAction: ActionHandler = { parameters, success, failed, _ in
4343
if let text = parameters["text"] {
4444
print(text)
4545
let formatter = DateFormatter()
4646
formatter.dateStyle = .long
4747
formatter.timeStyle = .medium
48-
48+
4949
let dateString = formatter.string(from: Date())
5050
success(["text": text, "date": dateString])
5151
} else {
5252
failed(DemoError.noText)
5353
}
5454
}
55-
55+
5656
}

SampleApp/CallbackURLKitDemo/ViewController.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import CallbackURLKit
1717
#endif
1818

1919
extension ViewController {
20-
20+
2121
override func viewDidLoad() {
2222
super.viewDidLoad()
2323
}
@@ -28,19 +28,19 @@ extension ViewController {
2828
try chrome.open(url: "http://www.google.com")
2929
} catch CallbackURLKitError.appWithSchemeNotInstalled(let scheme) {
3030
print("chrome(\(scheme)) not installed or not implement x-callback-url in current os")
31-
31+
3232
} catch CallbackURLKitError.callbackURLSchemeNotDefined {
3333
print("current app scheme not defined")
3434
} catch let e {
3535
print("exception \(e)")
3636
}
3737
}
38-
38+
3939
@IBAction func printAction(_ sender: AnyObject!) {
4040
do {
4141
try CallbackURLKitDemo.instance.printMessage(
4242
"a message %20 % = &toto=a",
43-
onSuccess: { parameters in
43+
onSuccess: { parameters in
4444
print("parameters \(String(describing: parameters))")
4545
},
4646
onFailure: { error in
@@ -49,20 +49,20 @@ extension ViewController {
4949
)
5050
} catch CallbackURLKitError.appWithSchemeNotInstalled(let scheme) {
5151
print("\(scheme) not installed or not implement x-callback-url in current os")
52-
52+
5353
} catch CallbackURLKitError.callbackURLSchemeNotDefined {
5454
print("current app scheme not defined")
5555
} catch let e {
5656
print("exception \(e)")
5757
}
5858
}
59-
59+
6060
@IBAction func ulysseAuthorize(_ sender: AnyObject!) {
6161
let ulysses = Ulysses()
6262
do {
6363
try ulysses.authorize(
6464
appName: Manager.shared.callbackURLScheme ?? "callbackUrlKit",
65-
onSuccess: { token in
65+
onSuccess: { token in
6666
print("token \(token)")
6767

6868
// try? ulysses.newSheet(text: "test")
@@ -71,17 +71,15 @@ extension ViewController {
7171
print("\(error)")
7272
}
7373
)
74-
74+
7575
} catch CallbackURLKitError.appWithSchemeNotInstalled(let scheme) {
7676
print("chrome(\(scheme)) not installed or not implement x-callback-url in current os")
77-
77+
7878
} catch CallbackURLKitError.callbackURLSchemeNotDefined {
7979
print("current app scheme not defined")
8080
} catch let e {
8181
print("exception \(e)")
8282
}
8383
}
84-
8584

8685
}
87-

Sources/CallbackURLKit.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ public typealias SuccessCallback = (Parameters?) -> Void
3535
public typealias FailureCallback = (FailureCallbackError) -> Void
3636
public typealias CancelCallback = () -> Void
3737

38-
3938
// MARK: global functions
4039

41-
4240
// Perform an action on client application
4341
// - Parameter action: The action to perform.
4442
// - Parameter urlScheme: The urlScheme for application to apply action.
@@ -70,7 +68,7 @@ public protocol FailureCallbackError: Error {
7068
var message: String {get}
7169
}
7270
extension FailureCallbackError {
73-
public var XCUErrorParameters: Parameters {
71+
public var XCUErrorParameters: Parameters {
7472
return [kXCUErrorCode: "\(self.code)", kXCUErrorMessage: self.message]
7573
}
7674
public var XCUErrorQuery: String {
@@ -95,7 +93,7 @@ extension FailureCallbackError {
9593
}
9694

9795
// Framework errors
98-
public enum CallbackURLKitError : Error {
96+
public enum CallbackURLKitError: Error {
9997
// It's seems that application with specified scheme has not installed
10098
case appWithSchemeNotInstalled(scheme: String)
10199
// Failed to create NSURL for request
@@ -121,10 +119,9 @@ let kXCUErrorMessage = "errorMessage"
121119
// URL to open if the requested action is cancelled by the user. In the case where the target app offer the user the option to “cancel” the requested action, without a success or error result, this the the URL that should be opened to return the user to the source app.
122120
let kXCUCancel = "x-cancel"
123121

124-
125122
// MARK: - framework strings
126123

127124
let kResponse = "response"
128-
let kResponseType = "responseType";
125+
let kResponseType = "responseType"
129126
let kRequestID = "requestID"
130127
let protocolKeys = [kResponse, kResponseType, kRequestID]

Sources/Client.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ open class Client {
3232

3333
open var urlScheme: String
3434
open var manager: Manager?
35-
35+
3636
public init(urlScheme: String) {
3737
self.urlScheme = urlScheme
3838
}
39-
39+
4040
open var appInstalled: Bool {
41-
guard let url = URL(string:"\(self.urlScheme)://dummy") else {
41+
guard let url = URL(string: "\(self.urlScheme)://dummy") else {
4242
return false
4343
}
4444
#if os(iOS) || os(tvOS)
4545
return UIApplication.shared.canOpenURL(url)
46-
46+
4747
#elseif os(OSX)
4848
return NSWorkspace.shared.urlForApplication(toOpen: url) != nil
4949
#endif
@@ -60,11 +60,11 @@ open class Client {
6060

6161
open func perform(action: Action, parameters: Parameters = [:],
6262
onSuccess: SuccessCallback? = nil, onFailure: FailureCallback? = nil, onCancel: CancelCallback? = nil) throws {
63-
63+
6464
let request = Request(
6565
ID: UUID().uuidString, client: self,
6666
action: action, parameters: parameters,
67-
successCallback: onSuccess, failureCallback: onFailure, cancelCallback: onCancel
67+
successCallback: onSuccess, failureCallback: onFailure, cancelCallback: onCancel
6868
)
6969

7070
let manager = self.manager ?? Manager.shared
@@ -74,7 +74,7 @@ open class Client {
7474
// Return an error according to url, could be changed to fulfiled your need
7575
open func error(code: String?, message: String?) -> FailureCallbackError {
7676
let codeInt: Int
77-
if let c = code, let ci = Int(c) {
77+
if let c = code, let ci = Int(c) {
7878
codeInt = ci
7979
} else {
8080
codeInt = ErrorCode.missingErrorCode.rawValue

Sources/Extensions.swift

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import Foundation
2626
// MARK: String
2727
extension String {
2828

29-
var toQueryDictionary: [String : String] {
30-
var result: [String : String] = [String : String]()
29+
var toQueryDictionary: [String: String] {
30+
var result: [String: String] = [String: String]()
3131
let pairs: [String] = self.components(separatedBy: "&")
3232
for pair in pairs {
3333
let comps: [String] = pair.components(separatedBy: "=")
@@ -43,17 +43,17 @@ extension String {
4343
var queryEncodeRFC3986: String {
4444
let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
4545
let subDelimitersToEncode = "!$&'()*+,;="
46-
46+
4747
var allowedCharacterSet = CharacterSet.urlQueryAllowed
48-
allowedCharacterSet.remove(charactersIn : generalDelimitersToEncode + subDelimitersToEncode)
49-
48+
allowedCharacterSet.remove(charactersIn: generalDelimitersToEncode + subDelimitersToEncode)
49+
5050
return self.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) ?? self
5151
}
52-
52+
5353
var queryEncode: String {
5454
return self.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? self
5555
}
56-
56+
5757
var queryDecode: String {
5858
return self.removingPercentEncoding ?? self
5959
}
@@ -73,31 +73,30 @@ extension Dictionary {
7373
}
7474
return parts.joined(separator: "&") as String
7575
}
76-
76+
7777
fileprivate func join(_ other: Dictionary) -> Dictionary {
7878
var joinedDictionary = Dictionary()
79-
79+
8080
for (key, value) in self {
8181
joinedDictionary.updateValue(value, forKey: key)
8282
}
83-
83+
8484
for (key, value) in other {
8585
joinedDictionary.updateValue(value, forKey: key)
8686
}
87-
87+
8888
return joinedDictionary
8989
}
90-
90+
9191
init(_ pairs: [Element]) {
9292
self.init()
9393
for (k, v) in pairs {
9494
self[k] = v
9595
}
9696
}
97-
98-
}
99-
func +<K, V> (left: [K : V], right: [K : V]) -> [K : V] { return left.join(right) }
10097

98+
}
99+
func +<K, V> (left: [K: V], right: [K: V]) -> [K: V] { return left.join(right) }
101100

102101
// MARK: NSURLComponents
103102
extension URLComponents {
@@ -125,8 +124,7 @@ extension URLComponents {
125124
self.percentEncodedQuery = add
126125
}
127126
}
128-
127+
129128
}
130129

131130
func &= (left: inout URLComponents, right: String) { left.addToQuery(right) }
132-

0 commit comments

Comments
 (0)