Skip to content

Commit

Permalink
modify swift format
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmyveradin committed Jul 18, 2024
1 parent 028c5bf commit ec834de
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct AddFavoriteLocationsSheet: View {
.padding(.horizontal, 16)

List {
if search.isEmpty, let userLocation = userLocation {
if search.isEmpty, let userLocation {
Button(action: {
switch UserDefaultsServices.shared.saveFavoriteLocationData(data: userLocation) {
case .success:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public struct OriginDestinationSheetView: View {
// swiftlint:enable function_body_length
private func recentsSection() -> some View {
if sheetEnvironment.recentLocations.isEmpty {
return AnyView(EmptyView())
AnyView(EmptyView())
} else {
return AnyView(
AnyView(
Section(content: {
ForEach(Array(sheetEnvironment.recentLocations.prefix(5)), content: { location in
VStack(alignment: .leading) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public struct OriginDestinationSheetView: View {

private func currentUserSection() -> some View {
Group {
if let userLocation = userLocation {
if let userLocation {
Button(action: {
switch UserDefaultsServices.shared.saveRecentLocations(data: userLocation) {
case .success:
Expand Down Expand Up @@ -222,7 +222,7 @@ public struct OriginDestinationSheetView: View {
.padding(.horizontal, 16)

List {
if search.isEmpty && isSearchFocused {
if search.isEmpty, isSearchFocused {
currentUserSection()
} else if search.isEmpty {
favoritesSection()
Expand Down
4 changes: 2 additions & 2 deletions OTPKit/Services/LocationServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public final class LocationService: NSObject, ObservableObject, MKLocalSearchCom
let search = MKLocalSearch(request: searchRequest)

search.start { [weak self] response, error in
guard let self = self, let response = response else {
if let error = error {
guard let self, let response else {
if let error {
print("Error performing local search: \(error)")
}
return
Expand Down
1 change: 0 additions & 1 deletion OTPKit/Services/MapExtensionServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import MapKit
import SwiftUI


/// Manage Map extension such as markers, etc
public final class MapExtensionServices: ObservableObject {
public static let shared = MapExtensionServices()
Expand Down
16 changes: 6 additions & 10 deletions OTPKit/Services/UserDefaultsServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public final class UserDefaultsServices {
}

func saveFavoriteLocationData(data: Location) -> Result<Void, Error> {
var locations: [Location]

switch getFavoriteLocationsData() {
var locations: [Location] = switch getFavoriteLocationsData() {
case let .success(existingLocations):
locations = existingLocations
existingLocations
case .failure:
locations = []
[]
}

locations.append(data)
Expand Down Expand Up @@ -98,13 +96,11 @@ public final class UserDefaultsServices {
}

func saveRecentLocations(data: Location) -> Result<Void, Error> {
var locations: [Location]

switch getFavoriteLocationsData() {
var locations: [Location] = switch getFavoriteLocationsData() {
case let .success(existingLocations):
locations = existingLocations
existingLocations
case .failure:
locations = []
[]
}

locations.insert(data, at: 0)
Expand Down
4 changes: 2 additions & 2 deletions OTPKitTests/Helpers/MockDataLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct MockDataResponse {

class MockTask: URLSessionDataTask {
override var progress: Progress {
return Progress()
Progress()
}

private var closure: (Data?, URLResponse?, Error?) -> Void
Expand Down Expand Up @@ -130,7 +130,7 @@ class MockDataLoader: NSObject, URLDataLoader {
// MARK: - URL Response

func buildURLResponse(URL: URL, statusCode: Int) -> HTTPURLResponse {
return HTTPURLResponse(
HTTPURLResponse(
url: URL,
statusCode: statusCode,
httpVersion: "2",
Expand Down
2 changes: 1 addition & 1 deletion OTPKitTests/Helpers/OTPTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class OTPTestCase: XCTestCase {
}

var userDefaultsSuiteName: String {
return String(describing: self)
String(describing: self)
}

// MARK: - Network and Data
Expand Down
2 changes: 1 addition & 1 deletion scripts/swiftformat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if [[ "$(uname -m)" == arm64 ]]; then
fi

if which swiftformat > /dev/null; then
swiftformat .
swiftformat . --swiftversion 5.9
else
echo "warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat"
fi

0 comments on commit ec834de

Please sign in to comment.