Skip to content

Commit

Permalink
Fix swift linter complained errors
Browse files Browse the repository at this point in the history
- Function name cannot start with upper case
- Class name cannot start with lower case
  • Loading branch information
HuiSF committed Nov 18, 2021
1 parent 1f79813 commit ddceaa7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SwiftAmplifyAnalyticsPinpointPlugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)

innerHandle(method: call.method, callArgs: call.arguments as Any?, result: result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)

innerHandle(method: call.method, callArgs: call.arguments as Any, result: result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SwiftAuthCognito: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)

if(call.method == "addPlugin"){
do {
Expand Down
14 changes: 7 additions & 7 deletions packages/amplify_core/ios/Classes/Support/AtomicResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
import Foundation

/// Thread-safe wrapper for [FlutterResult]. Prevents multiple replies and automically posts results to the main thread.
public func AtomicResult(_ result: @escaping FlutterResult, _ methodName: String) -> FlutterResult {
return atomicResult(result, methodName).send
public func atomicResult(_ result: @escaping FlutterResult, _ methodName: String) -> FlutterResult {
return AtomicResult(result, methodName).send
}

private class atomicResult {
private class AtomicResult {
let result: FlutterResult

/// The method call which initiated this result.
let methodName: String

/// Whether a reply has already been sent.
var isSent = false

init(_ result: @escaping FlutterResult, _ methodName: String) {
self.result = result
self.methodName = methodName
}

func send(_ value: Any?) {
DispatchQueue.main.async { [self] in
guard !isSent else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SwiftAmplifyDataStorePlugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)
var arguments: [String: Any] = [:]
do {
if(call.arguments != nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class AtomicResultTests: XCTestCase {
}
XCTAssertEqual(strValue, expected)
}
let atomicResult = AtomicResult(result, #function)
atomicResult(expected)
let aResult = atomicResult(result, #function)
aResult(expected)
waitForExpectations(timeout: 1)
}

Expand All @@ -52,18 +52,18 @@ class AtomicResultTests: XCTestCase {
}
XCTAssertEqual(errValue, expected)
}
let atomicResult = AtomicResult(result, #function)
atomicResult(expected)
let aResult = atomicResult(result, #function)
aResult(expected)
waitForExpectations(timeout: 0.1)
}

func test_multiple_synchronous_replies_are_not_sent() {
let result: FlutterResult = { _ in
OSAtomicIncrement32(&self.counter)
}
let atomicResult = AtomicResult(result, #function)
atomicResult(nil)
atomicResult(nil)
let aResult = atomicResult(result, #function)
aResult(nil)
aResult(nil)
let exp = expectation(description: #function)
DispatchQueue.main.async { [self] in
XCTAssertEqual(counter, 1)
Expand All @@ -76,11 +76,11 @@ class AtomicResultTests: XCTestCase {
let result: FlutterResult = { _ in
OSAtomicIncrement32(&self.counter)
}
let atomicResult = AtomicResult(result, #function)
let aResult = atomicResult(result, #function)

DispatchQueue.global().sync {
DispatchQueue.concurrentPerform(iterations: 1000) { i in
atomicResult(nil)
aResult(nil)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_flutter/ios/Classes/SwiftAmplify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SwiftAmplify: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)

switch call.method {
case "configure":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SwiftAmplifyStorageS3Plugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let result = AtomicResult(result, call.method)
let result = atomicResult(result, call.method)

if(call.method == "addPlugin"){
do {
Expand Down

0 comments on commit ddceaa7

Please sign in to comment.