Skip to content

Commit

Permalink
Switch to Apple's swift-format tool
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Sep 17, 2024
1 parent b1d3dea commit b9a3fac
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 161 deletions.
5 changes: 5 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"indentation": {
"spaces": 4
}
}
2 changes: 2 additions & 0 deletions Fyreplace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
4DE785842C88EF8C000EC4E5 /* RequestIdMiddleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestIdMiddleware.swift; sourceTree = "<group>"; };
4DE785872C88F392000EC4E5 /* HTTPField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPField.swift; sourceTree = "<group>"; };
4DE785942C8B17AE000EC4E5 /* SubmitOrCancel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubmitOrCancel.swift; sourceTree = "<group>"; };
4DF3737F2C99C23D0008AB04 /* .swift-format */ = {isa = PBXFileReference; explicitFileType = text.json; path = ".swift-format"; sourceTree = "<group>"; };
4DFB906F2C5908DE00D4DABF /* LoginScreenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenTests.swift; sourceTree = "<group>"; };
4DFB90752C59173C00D4DABF /* RegisterScreenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterScreenTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -273,6 +274,7 @@
4D54C93C2BF26090001DE071 /* FyreplaceTests */,
4D54C9462BF26090001DE071 /* FyreplaceUITests */,
4D54C9632BF28695001DE071 /* .gitignore */,
4DF3737F2C99C23D0008AB04 /* .swift-format */,
4D0DDC292C18A467006CD503 /* .xcode-version */,
4D6641DB2C5B963500BE3D07 /* .ios-test-version */,
4DCEF8652C452EBA00F53085 /* .env-example */,
Expand Down
12 changes: 7 additions & 5 deletions Fyreplace/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ struct Config {
return Client(
serverURL: url(for: environment),
configuration: .init(dateTranscoder: .iso8601WithFractionalSeconds),
transport: URLSessionTransport(configuration: .init(session: .init(configuration: configuration))),
transport: URLSessionTransport(
configuration: .init(session: .init(configuration: configuration))
),
middlewares: [RequestIdMiddleware(), AuthenticationMiddleware()]
)
}
Expand All @@ -109,17 +111,17 @@ struct Config {
}
}

private extension [String: Any] {
func string(_ key: String) -> String? {
extension [String: Any] {
fileprivate func string(_ key: String) -> String? {
return self[key] as? String
}

func url(_ key: String) -> URL? {
fileprivate func url(_ key: String) -> URL? {
guard let s = string(key) else { return nil }
return .init(string: s)
}

func dictionary(_ key: String) -> [String: Any]? {
fileprivate func dictionary(_ key: String) -> [String: Any]? {
return self[key] as? [String: Any]
}
}
Expand Down
7 changes: 4 additions & 3 deletions Fyreplace/Data/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct Keychain {
info[kSecReturnData] = true
var itemReference: CFTypeRef?
guard SecItemCopyMatching(info as CFDictionary, &itemReference) == errSecSuccess,
let data = itemReference as? Data,
let value = String(data: data, encoding: .utf8)
let data = itemReference as? Data,
let value = String(data: data, encoding: .utf8)
else { return "" }
return value
}
Expand All @@ -33,8 +33,9 @@ struct Keychain {
func set(_ value: String) -> Bool {
guard !value.isEmpty else { return delete() }
let data = value.data(using: .utf8)
let attributes = [kSecValueData: data] as CFDictionary

if SecItemUpdate(query as CFDictionary, [kSecValueData: data] as CFDictionary) == errSecSuccess {
if SecItemUpdate(query as CFDictionary, attributes) == errSecSuccess {
return true
} else {
var info = query
Expand Down
2 changes: 1 addition & 1 deletion Fyreplace/Data/Tokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func scheduleTokenRefresh() {

func refreshToken(using api: APIProtocol) async -> String? {
guard let response = try? await api.getNewToken().ok,
let newToken = try? await String(collecting: response.body.plainText, upTo: 1024)
let newToken = try? await String(collecting: response.body.plainText, upTo: 1024)
else { return nil }
return newToken
}
4 changes: 2 additions & 2 deletions Fyreplace/Extensions/Array+RawRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ extension Array: RawRepresentable where Element: Codable {
public init?(rawValue: String) {
self.init()
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode([Element].self, from: data)
let result = try? JSONDecoder().decode([Element].self, from: data)
else { return nil }
result.forEach { append($0) }
}

public var rawValue: String {
guard let data = try? JSONEncoder().encode(self),
let value = String(data: data, encoding: .utf8)
let value = String(data: data, encoding: .utf8)
else { return "[]" }
return value
}
Expand Down
Loading

0 comments on commit b9a3fac

Please sign in to comment.