Tusker/Tusker/Screens/Utilities/UIAlertController+Visibilit...

34 lines
1009 B
Swift
Raw Normal View History

2018-10-26 01:54:07 +00:00
//
// UIAlertController+Visibility.swift
// Tusker
//
// Created by Shadowfacts on 10/25/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
extension UIAlertController {
convenience init(currentVisibility: Visibility?, completion: @escaping (Visibility?) -> Void) {
2018-10-26 01:54:07 +00:00
self.init(title: "Post Visibility", message: nil, preferredStyle: .actionSheet)
for visibility in Visibility.allCases {
2018-10-26 01:54:07 +00:00
let action = UIAlertAction(title: visibility.displayName, style: .default) { (_) in
completion(visibility)
}
if visibility == currentVisibility {
action.setValue(true, forKey: "checked")
}
2019-06-14 00:53:17 +00:00
action.setValue(UIImage(systemName: visibility.imageName), forKey: "image")
2018-10-26 01:54:07 +00:00
addAction(action)
}
addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in
completion(nil)
}))
}
}