Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix(swiftformat): executed "swiftformat ."
Browse files Browse the repository at this point in the history
  • Loading branch information
migueltorcha committed Sep 30, 2022
1 parent 780dc7e commit 2b5c56a
Show file tree
Hide file tree
Showing 128 changed files with 1,616 additions and 1,303 deletions.
39 changes: 24 additions & 15 deletions Example/Harmony/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
// Copyright (c) 2017 Mobile Jazz. All rights reserved.
//

import UIKit
import Harmony
import SwiftUI
import UIKit

let applicationComponent: ApplicationComponent = ApplicationDefaultModule()

enum ApplicationUI {
case UIKit
case SwiftUI
}

// Modify this property to change the UI implementation!
let applicationUI: ApplicationUI = .SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var observable: Observable<Int>!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
switch applicationUI {
case .UIKit:
let splash = SplashViewController()
Expand Down Expand Up @@ -59,25 +60,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
func applicationWillResignActive(_: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types
// of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the
// application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games
// should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
func applicationDidEnterBackground(_: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough
// application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of
// applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
func applicationWillEnterForeground(_: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the
// changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
func applicationDidBecomeActive(_: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application
// was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
func applicationWillTerminate(_: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also
// applicationDidEnterBackground:.
}
}
8 changes: 4 additions & 4 deletions Example/Harmony/Core/ApplicationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2021 CocoaPods. All rights reserved.
//

import Harmony
import Alamofire
import Harmony

// Enabling vastra service as an object validation
extension VastraService: ObjectValidation {}
Expand All @@ -17,14 +17,14 @@ protocol ApplicationComponent {
}

class ApplicationDefaultModule: ApplicationComponent {

private lazy var logger: Logger = DeviceConsoleLogger()
private lazy var backgroundExecutor: Executor = DispatchQueueExecutor()

private lazy var apiClient: Session = {
// Alamofire Session Manager
let sessionManager = Session(interceptor: BaseURLRequestAdapter(URL(string: "https://demo3068405.mockable.io")!,
[UnauthorizedStatusCodeRequestRetrier()]))
let sessionManager =
Session(interceptor: BaseURLRequestAdapter(URL(string: "https://demo3068405.mockable.io")!,
[UnauthorizedStatusCodeRequestRetrier()]))
return sessionManager
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@

import Foundation

import Harmony
import Alamofire
import Harmony

extension ItemEntity {
fileprivate static var fromNetworkMap: [String: String] {
private extension ItemEntity {
static var fromNetworkMap: [String: String] {
return ["image-url": "imageURL"]
}

fileprivate static var toNetworkMap: [String: String] {
static var toNetworkMap: [String: String] {
return ["imageURL": "image-url"]
}
}

class ItemNetworkDataSource: GetDataSource {

typealias T = ItemEntity

var sessionManager: Session
Expand Down Expand Up @@ -56,9 +55,10 @@ private extension ItemNetworkDataSource {
guard let json = data as? [String: AnyObject] else {
throw CoreError.NotFound()
}
let future = json.decodeAs(ItemEntity.self, keyDecodingStrategy: .map(ItemEntity.fromNetworkMap)) { item in
item.lastUpdate = Date()
}
let future = json
.decodeAs(ItemEntity.self, keyDecodingStrategy: .map(ItemEntity.fromNetworkMap)) { item in
item.lastUpdate = Date()
}
return future
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import Harmony

class ItemToItemEntityMapper: Mapper<Item, ItemEntity> {
override func map(_ from: Item) throws -> ItemEntity {
return ItemEntity(id: from.id, name: from.name, price: from.price, count: from.count, imageURL: from.imageURL)
return ItemEntity(
id: from.id,
name: from.name,
price: from.price,
count: from.count,
imageURL: from.imageURL
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ItemListDefaultPresenter: ItemListPresenter {

func onActionReloadList() {
view?.onDisplayProgressHud(show: true)
self.getItems.execute(MainSyncOperation()).then { items in
getItems.execute(MainSyncOperation()).then { items in
self.view?.onDisplayProgressHud(show: false)
self.view?.onDisplayItems(items)
}.fail { error in
Expand Down
18 changes: 10 additions & 8 deletions Example/Harmony/Core/Features/Item/ItemProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2021 CocoaPods. All rights reserved.
//

import Harmony
import Alamofire
import Harmony

protocol ItemComponent {
func itemListPresenter(view: ItemListPresenterView) -> ItemListPresenter
Expand All @@ -30,26 +30,28 @@ class ItemDefaultModule: ItemComponent {
// To debug the UI upon random API behavior, adding this intermediate layer
let itemNetworkDataSource = DebugDataSource(DataSourceAssembler(get: baseDataSource),
delay: .sync(0.5),
error: .error(CoreError.Failed("Debug Fail"), probability: 0.01),
error: .error(
CoreError.Failed("Debug Fail"),
probability: 0.01
),
logger: DeviceConsoleLogger())

// Adding retry behavior in case of error
let networkDataSource = RetryDataSource(itemNetworkDataSource, retryCount: 1) { error in
return error._code == NSURLErrorTimedOut && error._domain == NSURLErrorDomain
error._code == NSURLErrorTimedOut && error._domain == NSURLErrorDomain
}
return AnyDataSource(networkDataSource)
}()

private lazy var storageDataSource: AnyDataSource<ItemEntity> = {
return AnyDataSource(
AnyDataSource(
DataSourceMapper(dataSource: self.storage,
toInMapper: EncodableToDataMapper<ItemEntity>(),
toOutMapper: DataToDecodableMapper<ItemEntity>())
)
}()

private lazy var repository: AnyRepository<Item> = {

let vastra = VastraService([VastraTimestampStrategy()])
let storageValidationDataSource = DataSourceValidator(dataSource: self.storageDataSource,
validator: vastra)
Expand All @@ -64,11 +66,11 @@ class ItemDefaultModule: ItemComponent {
}()

private func getAllItemsInteractor() -> GetAllItemsInteractor {
return GetAllItemsInteractor(executor: self.executor,
getItems: Interactor.GetAllByQuery(DirectExecutor(), self.repository))
return GetAllItemsInteractor(executor: executor,
getItems: Interactor.GetAllByQuery(DirectExecutor(), repository))
}

func itemListPresenter(view: ItemListPresenterView) -> ItemListPresenter {
return ItemListDefaultPresenter(view, self.getAllItemsInteractor())
return ItemListDefaultPresenter(view, getAllItemsInteractor())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
import Alamofire

class UnauthorizedStatusCodeRequestRetrier: RequestRetrier {
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {
func retry(_ request: Request, for _: Session, dueTo _: Error, completion: @escaping (RetryResult) -> Void) {
if request.response?.statusCode == 401 {
// TODO: Logout user
}
Expand Down
14 changes: 11 additions & 3 deletions Example/Harmony/Screens/SwiftUI/ItemDetail/ItemDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Mobile Jazz. All rights reserved.
//

import SwiftUI
import Kingfisher
import SwiftUI

struct ItemDetailView: View {
var item: Item
Expand All @@ -24,7 +24,7 @@ struct ItemDetailView: View {
Spacer()
Text("\(Int(item.price))")
.font(.system(size: 80, weight: .bold))
.foregroundColor(Color(red: 0, green: 190.0/256.0, blue: 176.0/256.0))
.foregroundColor(Color(red: 0, green: 190.0 / 256.0, blue: 176.0 / 256.0))
Spacer()
}.navigationTitle(item.name)
}
Expand All @@ -33,7 +33,15 @@ struct ItemDetailView: View {
struct ItemDetailView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ItemDetailView(item: Item(id: "1", name: "Macbook Pro", price: 1234.56, count: 12, imageURL: URL(string: "(https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/mbp-spacegray-select-202206_GEO_ES?wid=904&hei=840&fmt=jpeg&qlt=90&.v=1654014007395")))
ItemDetailView(item: Item(
id: "1",
name: "Macbook Pro",
price: 1234.56,
count: 12,
imageURL: URL(
string: "(https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/mbp-spacegray-select-202206_GEO_ES?wid=904&hei=840&fmt=jpeg&qlt=90&.v=1654014007395"
)
))
}
}
}
6 changes: 2 additions & 4 deletions Example/Harmony/Screens/SwiftUI/ItemList/ItemListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// Copyright © 2022 CocoaPods. All rights reserved.
//

import SwiftUI
import Kingfisher
import SwiftUI

struct ItemListView: View {

@StateObject var viewState: ItemListViewState

var body: some View {
Expand Down Expand Up @@ -52,7 +51,7 @@ struct ItemListView: View {
Spacer()
Text("\(Int(item.price))")
.font(.system(size: 23, weight: .bold))
.foregroundColor(Color(red: 0, green: 190.0/256.0, blue: 176.0/256.0))
.foregroundColor(Color(red: 0, green: 190.0 / 256.0, blue: 176.0 / 256.0))
}
}
}
Expand All @@ -68,7 +67,6 @@ struct ItemListView: View {
} label: {
Image(systemName: "arrow.clockwise")
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation

class ItemListViewState: ObservableObject, ItemListPresenterView {

@Published var items: [Item]
@Published var isLoading: Bool = true
@Published var error: Error?
Expand All @@ -23,12 +22,12 @@ class ItemListViewState: ObservableObject, ItemListPresenterView {
lazy var presenter = applicationComponent.itemComponent.itemListPresenter(view: self)

func onDisplayProgressHud(show: Bool) {
self.isLoading = show
isLoading = show
}

func onDisplayItems(_ items: [Item]) {
self.items = items
self.error = nil
error = nil
}

func onNavigateToItem(_ item: Item) {
Expand Down
3 changes: 1 addition & 2 deletions Example/Harmony/Screens/SwiftUI/Splash/SplashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct SplashView: View {
var body: some View {
ZStack {
Color(red: 0, green: 190.0/256.0, blue: 176.0/256.0)
Color(red: 0, green: 190.0 / 256.0, blue: 176.0 / 256.0)
.ignoresSafeArea()
VStack {
Text("Splash")
Expand All @@ -20,7 +20,6 @@ struct SplashView: View {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: Color.white))
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import UIKit

class ItemDetailViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var unitsLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet var imageView: UIImageView!
@IBOutlet var nameLabel: UILabel!
@IBOutlet var unitsLabel: UILabel!
@IBOutlet var priceLabel: UILabel!

// Temp item to obtain it from previous screen.
// This could be improved.
Expand All @@ -23,7 +22,7 @@ class ItemDetailViewController: UIViewController {
super.viewWillAppear(animated)

if let item = item {
self.title = item.name
title = item.name

nameLabel.text = item.name
unitsLabel.text = "\(item.count) units"
Expand Down
11 changes: 5 additions & 6 deletions Example/Harmony/Screens/UIKit/ItemList/ItemCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// Copyright © 2017 Mobile Jazz. All rights reserved.
//

import UIKit
import Kingfisher
import UIKit

class ItemCell: UITableViewCell {

@IBOutlet weak var itemImageView: UIImageView!
@IBOutlet weak var itemNameLabel: UILabel!
@IBOutlet weak var itemCountLabel: UILabel!
@IBOutlet weak var itemPriceLabel: UILabel!
@IBOutlet var itemImageView: UIImageView!
@IBOutlet var itemNameLabel: UILabel!
@IBOutlet var itemCountLabel: UILabel!
@IBOutlet var itemPriceLabel: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
Expand Down
Loading

0 comments on commit 2b5c56a

Please sign in to comment.