CVSKit is a collection of Swift extensions and utility for better programming.
Requirements
- iOS 10.0+
- Swift 4.2+
Installation
CVSKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CVSKit'
Features
Foundation/Extension
String+Extension
extension String {
func localized() -> String
func localized(with arguments: CVarArg...) -> String
var isValidEmail: Bool
var trimming: String
func toJsonObject() -> Any?
}
OptionSet+Extension
extension OptionSet {
func forEach(_ body: (Self) throws -> Void)
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Self) -> Result) -> Result
func enumerate() -> AnySequence<Self>
}
Collection+Extension
extension Array {
subscript(safe index: Int) -> Element?
var any: Element?
}
extension Collection {
func forEachStop(_ body: (Element, Int, inout Bool) -> Void)
}
extension Dictionary {
static func += (left: inout [Key: Value], right: [Key: Value])
static func + (left: [Key: Value], right: [Key: Value]) -> [Key: Value]
}
extension Array {
func toJson(prettyPrint: Bool = false) -> String?
func toJsonData(prettyPrint: Bool = false) -> Data?
}
extension Dictionary {
func toJson(prettyPrint: Bool = false) -> String?
func toJsonData(prettyPrint: Bool = false) -> Data?
}
DispatchQueue+Extension
extension DispatchQueue {
static var userInteractive: DispatchQueue
static var userInitiated: DispatchQueue
static var utility: DispatchQueue
static var background: DispatchQueue
func after(_ delay: TimeInterval, execute closure: @escaping () -> Void)
func async<Result>(execute: () -> Result, afterInMain mainExecute: (Result) -> Void)
}
Numeric+Extension
extension BinaryInteger {
static func |- (left: Self, right: Self) -> Self
}
extension BinaryFloatingPoint {
static func |- (left: Self, right: Self) -> Self
}
extension BinaryInteger {
var humanReadableFileSize: String
}
Date+Extension
public enum DateUnit {
case day, month, year
}
extension Date {
func startOfUnit(_ unit: DateUnit) -> Date
func nextStartOfUnit(_ unit: DateUnit) -> Date
}
Comparable+Extension
extension Comparable {
func boundary(minimum: Self, maximum: Self) -> Self
}
CoreGraphics/Extension
CGSize+Extension
extension CGSize {
var rect: CGRect
var area: CGFloat
func resized(constrainedPixel: Int, scale: CGFloat = UIScreen.main.scale) -> CGSize
func resized(toScale: CGFloat) -> CGSize
func resizedAspectFit(fitSize: CGSize) -> CGSize
}
UIKit/Extension
UIEdgeInsets+Extension
extension UIEdgeInsets {
var horizontal: CGFloat
var vertical: CGFloat
var leftTop: CGPoint
var rightBottom: CGPoint
}
UIDevice+Extension
extension UIDevice {
static var isPhone: Bool
static var isPad: Bool
}
UIColor+Extension
extension UIColor {
convenience init(rgb: Int, alpha: CGFloat = 1)
convenience init(argb: Int)
convenience init?(hex: String, alpha: CGFloat = 1)
}
UIImage+Extension
extension UIImage {
static func create(size: CGSize, opaque: Bool, scale: CGFloat, draw: (CGContext) -> Void) -> UIImage
convenience init(color: UIColor, size: CGSize)
var stretchable: UIImage
static func createAsync(withData data: Data, completion: (UIImage?) -> Void)
func with(alpha: CGFloat) -> UIImage
func createAsync(withAlpha alpha: CGFloat, completion: (UIImage) -> Void)
func with(tintColor: UIColor) -> UIImage
func createAsync(withTintColor tintColor: UIColor, completion: (UIImage) -> Void)
func with(edgeInsets: UIEdgeInsets, backgroundColor: UIColor) -> UIImage
func createAsync(withEdgeInsets edgeInsets: UIEdgeInsets, completion:(UIImage) -> Void)
func circled() -> UIImage
func circledAsync(completion: (UIImage) -> Void)
func squareCircled() -> UIImage
func squareCircledAsync(completion: (UIImage) -> Void)
extension UIImage {
func resized(toSize: CGSize, scale: CGFloat?) -> UIImage
func resizedAsync(toSize: CGSize, scale: CGFloat?, completion: (UIImage) -> Void)
func resized(withConstrainedPixel pixel: Int) -> UIImage
func resizedAsync(withConstrainedPixel pixel: Int, completion:(UIImage) -> Void)
func resized(withAspectFitSize fitSize: CGSize) -> UIImage
func resizedAsync(withAspectFitSize fitSize: CGSize, completion: (UIImage) -> Void)
func resized(withAspectFillSize fillSize: CGSize) -> UIImage
func resizedAsync(withAspectFillSize fillSize: CGSize, completion: (UIImage) -> Void)
}
UIView+Extension
extension UIView.AutoresizingMask {
static var flexibleAll: UIView.AutoresizingMask { get }
static var flexibleVerticalMargin: UIView.AutoresizingMask { get }
static var flexibleHorizontalMargin: UIView.AutoresizingMask { get }
static var flexibleAllMargin: UIView.AutoresizingMask { get }
static var inflexibleLeftMargin: UIView.AutoresizingMask { get }
static var inflexibleRightMargin: UIView.AutoresizingMask { get }
static var inflexibleTopMargin: UIView.AutoresizingMask { get }
static var inflexibleBottomMargin: UIView.AutoresizingMask { get }
}
extension UIView {
var origin: CGPoint { get, set }
var size: CGSize { get, set }
var width: CGFloat { get, set }
var height: CGFloat { get, set }
func moveToVerticalCenter()
func moveToHorizontalCenter()
func moveToCenter()
func putAfter(of view: UIView, gap: CGFloat)
func putBefore(of view: UIView, gap: CGFloat)
func putAbove(of view: UIView, gap: CGFloat)
func putBelow(of view: UIView, gap: CGFloat)
}
extension UIView {
static func autoLayoutView() -> Self
func allConstraints(equalTo anchors: LayoutAnchorProvider) -> [NSLayoutConstraint]
}
extension UIView {
var asImage: UIImage { get }
static var isRightToLeft: Bool { get }
}
UIView+Animation
extension UIView {
func startRotating(clockwise: Bool, duration: Double, repeatCount: Float)
func stopRotating()
func startPulse(fromScale: CGFloat, toScale: CGFloat, duration: CFTimeInterval, repeatCount: Float)
func stopPulse()
func fadeTransition(_ duration: CFTimeInterval)
}
UIImageView+Extension
extension UIImageView {
static func autolayoutView(image: UIImage) -> Self
}
UIButton+Extension
extension UIButton {
static func autoLayoutView(type: UIButton.ButtonType) -> Self
func setSelectedTitle(_ title: String?)
func setBackgroundImage(_ image: UIImage?)
func setImage(_ image: UIImage?)
func setSelectedImage(_ image: UIImage?)
func setTitleColor(_ color: UIColor?)
var title: String? { get, set }
}
extension UIButton {
typealias ButtonAction = ((UIButton) -> Void)
func setAction(_ action: ButtonAction?)
}
extension UIControl {
func addTarget(_ target: Any?, action: Selector)
}
UILabel+Extension
extension UILabel {
static func autoLayoutView(font: UIFont?, color: UIColor?) -> Self
convenience init(font: UIFont?, color: UIColor?)
func sizeToFit(constrainedWidth: CGFloat)
}
extension UILabel {
static func measureSize(withText text: String, font: UIFont, numberOfLines: Int, constrainedWidth: CGFloat, lineBreakMode: NSLineBreakMode) -> CGSize
static func measureSize(withAttributedString string: NSAttributedString, numberOfLines: Int, constrainedWidth: CGFloat, lineBreakMode: NSLineBreakMode) -> CGSize
}
UITableView+Extension
protocol ReusableViewCell
extension UITableView {
static func autoLayoutView(_ style: UITableView.Style) -> Self
func dequeueReusableCell<Cell: ReusableViewCell>(initializer: (() -> Cell)?) -> Cell
func hideSeparatorsForEmptyRows()
var emptyDataView: UIView? { get, set }
func reloadData(completion: @escaping (UITableView) -> Void)
}
UIScrollView+Extension
extension UIScrollView {
var backportContentInset: UIEdgeInsets
}
UIBarButtonItem+Extension
extension UIBarButtonItem {
func setTitleColor(_ color: UIColor?, for: UIControl.State)
func setTitleFont(_ font: UIFont?, for: UIControl.State)
}
UIGestureRecognizer+Extension
extension UIGestureRecognizer {
typealias GestureAction = ((UIGestureRecognizer) -> Void)
func setAction(_ action: GestureAction?)
}
UIAlertController+Extension
extension UIAlertController {
static func alert(withtitle title: String?, message: String?) -> UIAlertController
static func actionSheet(withTitle title: String?, message: String?) -> UIAlertController
static func actionSheet(withTitle title: String?, message: String?, sourceView: UIView, sourceRect: CGRect) -> UIAlertController
func addDefaultAction(title: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertController
func addCancelAction(title: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertController
func addDestructiveAction(title: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertController
}
UIKit/Util
UIViewController+SwipeDismiss
extension UIViewController {
func configureSwipeDismiss(enabled: Bool)
}
protocol SwipeDismissViewControllerProtocol: NSObjectProtocol {
optional var shouldBeginSwipeDismiss: Bool { get }
optional var scrollViewForSwipeDismiss: UIScrollView { get }
optional var dimmingBackgroundViewForSwipeDismiss: UIView { get }
optional func willFinishSwipeDismiss()
optional func didFinishSwipeDismiss()
optional func didCancelSwipeDismiss()
}
HardwareModel
enum HardwareModel: String {
case iPhone, iPhone4, iPhone5, ...
case iPad, iPad2, iPadMini, ...
case iPod1G, iPod2G, iPod3G, ...
...
case unknown
}
SensitiveButton
class SensitiveButton: UIButton {
let hitTester = SensitiveHitTester()
}
class SensitiveHitTester: NSObject {
var extraHitEdgeInsets: UIEdgeInsets
func point(inside point: CGPoint, bounds: CGRect, with event: UIEvent?) -> Bool
}
ChameleonView
class ChameleonView: UIView {
var minFeel: CGFloat
var maxFeel: CGFloat
var feel: CGFloat
func set(colorAndLocations: [(UIColor, CGFloat)])
}
ChameleonView
class HorizontalPagingView: UIScrollView {
var pages: [UIView]
func setPage(at index: Int, animated: Bool)
var pageIndex: Int
}
CircularProgressView
class CircularProgressView: UIView {
var maxProgress: CGFloat
var progress: CGFloat
}
Author
zzangzio, [email protected]
License
CVSKit is available under the MIT license. See the LICENSE file for more info.