Skip to content

Commit 76a6fd2

Browse files
authored
[shared_preferences_foundation] Run swift-format on Swift files (#5933)
Run `swift-format` linter/formatter on Swift files. Part of turning on swift-format CI formatting #5928
1 parent 4dd91ce commit 76a6fd2

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

packages/shared_preferences/shared_preferences_foundation/darwin/Classes/SharedPreferencesPlugin.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import Foundation
66

77
#if os(iOS)
8-
import Flutter
8+
import Flutter
99
#elseif os(macOS)
10-
import FlutterMacOS
10+
import FlutterMacOS
1111
#endif
1212

1313
public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
1414
public static func register(with registrar: FlutterPluginRegistrar) {
1515
let instance = SharedPreferencesPlugin()
1616
// Workaround for https://github.com/flutter/flutter/issues/118103.
17-
#if os(iOS)
18-
let messenger = registrar.messenger()
19-
#else
20-
let messenger = registrar.messenger
21-
#endif
17+
#if os(iOS)
18+
let messenger = registrar.messenger()
19+
#else
20+
let messenger = registrar.messenger
21+
#endif
2222
UserDefaultsApiSetup.setUp(binaryMessenger: messenger, api: instance)
2323
}
2424

25-
func getAll(prefix: String, allowList: [String]?) -> [String? : Any?] {
25+
func getAll(prefix: String, allowList: [String]?) -> [String?: Any?] {
2626
return getAllPrefs(prefix: prefix, allowList: allowList)
2727
}
2828

@@ -47,21 +47,22 @@ public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
4747
for (key, _) in getAllPrefs(prefix: prefix, allowList: allowList) {
4848
defaults.removeObject(forKey: key)
4949
}
50-
return true
50+
return true
5151
}
5252

5353
/// Returns all preferences stored with specified prefix.
5454
/// If [allowList] is included, only items included will be returned.
5555
func getAllPrefs(prefix: String, allowList: [String]?) -> [String: Any] {
5656
var filteredPrefs: [String: Any] = [:]
57-
var allowSet: Set<String>?;
57+
var allowSet: Set<String>?
5858
if let allowList = allowList {
5959
allowSet = Set(allowList)
6060
}
6161
if let appDomain = Bundle.main.bundleIdentifier,
6262
let prefs = UserDefaults.standard.persistentDomain(forName: appDomain)
6363
{
64-
for (key, value) in prefs where (key.hasPrefix(prefix) && (allowSet == nil || allowSet!.contains(key))) {
64+
for (key, value) in prefs
65+
where (key.hasPrefix(prefix) && (allowSet == nil || allowSet!.contains(key))) {
6566
filteredPrefs[key] = value
6667
}
6768
}

packages/shared_preferences/shared_preferences_foundation/darwin/Tests/RunnerTests.swift

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import XCTest
66

7+
@testable import shared_preferences_foundation
8+
79
#if os(iOS)
8-
import Flutter
10+
import Flutter
911
#elseif os(macOS)
10-
import FlutterMacOS
12+
import FlutterMacOS
1113
#endif
1214

13-
@testable import shared_preferences_foundation
14-
1515
class RunnerTests: XCTestCase {
1616
let prefixes: [String] = ["aPrefix", ""]
1717

@@ -30,7 +30,7 @@ class RunnerTests: XCTestCase {
3030
XCTAssertEqual(storedValues["\(aPrefix)aDouble"] as! Double, 3.14, accuracy: 0.0001)
3131
XCTAssertEqual(storedValues["\(aPrefix)anInt"] as? Int, 42)
3232
XCTAssertEqual(storedValues["\(aPrefix)aString"] as? String, "hello world")
33-
XCTAssertEqual(storedValues["\(aPrefix)aStringList"] as? Array<String>, ["hello", "world"])
33+
XCTAssertEqual(storedValues["\(aPrefix)aStringList"] as? [String], ["hello", "world"])
3434
}
3535
}
3636

@@ -70,40 +70,40 @@ class RunnerTests: XCTestCase {
7070
XCTAssertNil(finalValues[testKey] as Any?)
7171
}
7272
}
73-
74-
func testClearWithNoAllowlist() throws {
75-
for aPrefix in prefixes {
76-
let plugin = SharedPreferencesPlugin()
77-
let testKey = "\(aPrefix)foo"
78-
plugin.setValue(key: testKey, value: 42)
79-
80-
// Make sure there is something to clear, so the test can't pass due to a set failure.
81-
let preRemovalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
82-
XCTAssertEqual(preRemovalValues[testKey] as? Int, 42)
83-
84-
// Then verify that clearing works.
85-
plugin.clear(prefix: aPrefix, allowList: nil)
86-
87-
let finalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
88-
XCTAssertNil(finalValues[testKey] as Any?)
89-
}
73+
74+
func testClearWithNoAllowlist() throws {
75+
for aPrefix in prefixes {
76+
let plugin = SharedPreferencesPlugin()
77+
let testKey = "\(aPrefix)foo"
78+
plugin.setValue(key: testKey, value: 42)
79+
80+
// Make sure there is something to clear, so the test can't pass due to a set failure.
81+
let preRemovalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
82+
XCTAssertEqual(preRemovalValues[testKey] as? Int, 42)
83+
84+
// Then verify that clearing works.
85+
plugin.clear(prefix: aPrefix, allowList: nil)
86+
87+
let finalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
88+
XCTAssertNil(finalValues[testKey] as Any?)
9089
}
91-
92-
func testClearWithAllowlist() throws {
93-
for aPrefix in prefixes {
94-
let plugin = SharedPreferencesPlugin()
95-
let testKey = "\(aPrefix)foo"
96-
plugin.setValue(key: testKey, value: 42)
97-
98-
// Make sure there is something to clear, so the test can't pass due to a set failure.
99-
let preRemovalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
100-
XCTAssertEqual(preRemovalValues[testKey] as? Int, 42)
101-
102-
plugin.clear(prefix: aPrefix, allowList: ["\(aPrefix)notfoo"])
103-
104-
let finalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
105-
XCTAssertEqual(finalValues[testKey] as? Int, 42)
106-
}
90+
}
91+
92+
func testClearWithAllowlist() throws {
93+
for aPrefix in prefixes {
94+
let plugin = SharedPreferencesPlugin()
95+
let testKey = "\(aPrefix)foo"
96+
plugin.setValue(key: testKey, value: 42)
97+
98+
// Make sure there is something to clear, so the test can't pass due to a set failure.
99+
let preRemovalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
100+
XCTAssertEqual(preRemovalValues[testKey] as? Int, 42)
101+
102+
plugin.clear(prefix: aPrefix, allowList: ["\(aPrefix)notfoo"])
103+
104+
let finalValues = plugin.getAll(prefix: aPrefix, allowList: nil)
105+
XCTAssertEqual(finalValues[testKey] as? Int, 42)
107106
}
108-
107+
}
108+
109109
}

packages/shared_preferences/shared_preferences_foundation/example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import UIKit
65
import Flutter
6+
import UIKit
77

88
@UIApplicationMain
99
@objc class AppDelegate: FlutterAppDelegate {

0 commit comments

Comments
 (0)