ProHUD/ProHUD/Guard/GuardModel.swift

80 lines
2.2 KiB
Swift
Raw Normal View History

2019-08-09 18:02:41 +08:00
//
// GuardModel.swift
// ProHUD
//
// Created by xaoxuu on 2019/8/9.
// Copyright © 2019 Titan Studio. All rights reserved.
//
import UIKit
public extension Guard {
2019-08-12 15:02:36 +08:00
class ViewModel {
2019-08-09 18:02:41 +08:00
/// ID
public var identifier = String(Date().timeIntervalSince1970)
public weak var vc: Guard?
}
}
public extension Guard.ViewModel {
///
/// - Parameter text:
@discardableResult func add(title: String?) -> UILabel {
return vc!.add(title: title)
}
///
/// - Parameter text:
@discardableResult func add(subTitle: String?) -> UILabel {
return vc!.add(subTitle: subTitle)
}
///
/// - Parameter text:
@discardableResult func add(message: String?) -> UILabel {
return vc!.add(message: message)
}
///
/// - Parameter style:
/// - Parameter title:
/// - Parameter action:
@discardableResult func add(action style: UIAlertAction.Style, title: String?, handler: (() -> Void)?) -> UIButton {
2019-08-12 15:02:36 +08:00
return vc!.insert(action: nil, style: style, title: title, handler: handler)
2019-08-09 18:02:41 +08:00
}
///
/// - Parameter index:
/// - Parameter style:
/// - Parameter title:
/// - Parameter handler:
2019-08-12 15:02:36 +08:00
@discardableResult func insert(action index: Int, style: UIAlertAction.Style, title: String?, handler: (() -> Void)?) -> UIButton {
return vc!.insert(action: index, style: style, title: title, handler: handler)
2019-08-09 18:02:41 +08:00
}
///
/// - Parameter index:
/// - Parameter style:
/// - Parameter title:
/// - Parameter handler:
2019-08-12 15:02:36 +08:00
func update(action index: Int, style: UIAlertAction.Style, title: String?, handler: (() -> Void)?) {
vc?.update(action: index, style: style, title: title, handler: handler)
2019-08-09 18:02:41 +08:00
}
///
/// - Parameter index:
func remove(action index: Int...) {
for (i, idx) in index.enumerated() {
2019-08-12 15:02:36 +08:00
vc?.remove(index: idx-i)
2019-08-09 18:02:41 +08:00
}
}
}