Skip to content

Commit

Permalink
Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhertz authored and actions-user committed Jul 15, 2020
1 parent aea0e10 commit 765a403
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions Sources/ComposableArchitecture/UIKit/Alert+UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,45 @@
//

#if canImport(UIKit)
import Foundation
import UIKit
import Foundation
import UIKit

extension AlertState.Button {
extension AlertState.Button {
func toUIKit(send: @escaping (Action) -> Void) -> UIAlertAction {
let action = { if let action = self.action { send(action) } }
switch self.type {
case let .cancel(.some(label)):
return .init(title: label, style: .cancel, handler: { _ in action() })
case .cancel(.none):
return .init(title: nil, style: .cancel, handler: { _ in action() })
case let .default(label):
return .init(title: label, style: .default, handler: { _ in action() })
case let .destructive(label):
return .init(title: label, style: .destructive, handler: { _ in action() })
}
let action = { if let action = self.action { send(action) } }
switch self.type {
case let .cancel(.some(label)):
return .init(title: label, style: .cancel, handler: { _ in action() })
case .cancel(.none):
return .init(title: nil, style: .cancel, handler: { _ in action() })
case let .default(label):
return .init(title: label, style: .default, handler: { _ in action() })
case let .destructive(label):
return .init(title: label, style: .destructive, handler: { _ in action() })
}
}
}
}

extension AlertState {
extension AlertState {
func toUIKit(send: @escaping (Action) -> Void) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)

if let primaryButton = primaryButton {
alert.addAction(primaryButton.toUIKit(send: send))
}
if let secondaryButton = secondaryButton {
alert.addAction(secondaryButton.toUIKit(send: send))
}
if let primaryButton = primaryButton {
alert.addAction(primaryButton.toUIKit(send: send))
}
if let secondaryButton = secondaryButton {
alert.addAction(secondaryButton.toUIKit(send: send))
}

return alert
return alert
}
}
}

public extension UIAlertController {
static func alert<Action>(_ alert: AlertState<Action>, send: @escaping (Action) -> Void) -> UIAlertController {
return alert.toUIKit(send: send)
extension UIAlertController {
public static func alert<Action>(_ alert: AlertState<Action>, send: @escaping (Action) -> Void)
-> UIAlertController
{
return alert.toUIKit(send: send)
}
}
}
#endif

0 comments on commit 765a403

Please sign in to comment.