Latest 0.4.0
Homepage https://github.com/zzangzio/CVSKit
License MIT
Platforms ios 10.0, requires ARC
Authors

CVSKit

CI Status
Version
License
Platform

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

String+Extension

“`swift
extension String {
func localized() -> String
func localized(with arguments: CVarArg…) -> String
var isValidEmail: Bool
var trimming: String
func toJsonObject() -> Any?
}
“`
go to source

OptionSet+Extension

“`swift
extension OptionSet {
func forEach(_ body: (Self) throws -> Void)
func reduce(_ initialResult: Result, _ nextPartialResult: (Result, Self) -> Result) -> Result
func enumerate() -> AnySequence
}
“`
go to source

Collection+Extension

“`swift
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?
}
“`
go to source

DispatchQueue+Extension

“`swift
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(execute: () -> Result, afterInMain mainExecute: (Result) -> Void)
}
“`
go to source

Numeric+Extension

“`swift
extension BinaryInteger {
static func |- (left: Self, right: Self) -> Self
}

extension BinaryFloatingPoint {
static func |- (left: Self, right: Self) -> Self
}

extension BinaryInteger {
var humanReadableFileSize: String
}
“`
go to source

Date+Extension

“`swift
public enum DateUnit {
case day, month, year
}

extension Date {
func startOfUnit(_ unit: DateUnit) -> Date
func nextStartOfUnit(_ unit: DateUnit) -> Date
}
“`
go to source

CoreGraphics

CGSize+Extension

“`swift
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
}
“`
go to source

CGRect+Extension

“`swift
extension CGRect {
func intersectionRatio(_ r2: CGRect) -> CGFloat
}
“`
go to source

UIKit

UIEdgeInsets+Extension

“`swift
extension UIEdgeInsets {
var horizontal: CGFloat
var vertical: CGFloat
var leftTop: CGPoint
var rightBottom: CGPoint
}
“`
go to source

UIColor+Extension

“`swift
extension UIColor {
convenience init(rgb: Int, alpha: CGFloat = 1)
convenience init(argb: Int)
convenience init?(hex: String, alpha: CGFloat = 1)
}
“`
go to source

UIImage+Extension

“`swift
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)
}
“`
go to source

HardwareModel

“`swift
enum HardwareModel: String {
case iPhone, iPhone4, iPhone5, …
case iPad, iPad2, iPadMini, …
case iPod1G, iPod2G, iPod3G, …

case unknown
}
“`
go to source

UIView+Extension

“`swift
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 }
}
“`
go to source

UIView+Animation

“`swift
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)
}
“`
go to source

UIImageView+Extension

“`swift
extension UIImageView {
static func autolayoutView(image: UIImage) -> Self
}
“`
go to source

UIButton+Extension

“`swift
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)
}
“`
go to source

UILabel+Extension

“`swift
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
}
“`
go to source

UITableView+Extension

“`swift
protocol ReusableViewCell

extension UITableView {
static func autoLayoutView(_ style: UITableView.Style) -> Self
func dequeueReusableCell(initializer: (() -> Cell)?) -> Cell
func hideSeparatorsForEmptyRows()
var emptyDataView: UIView? { get, set }
func reloadData(completion: @escaping (UITableView) -> Void)
}
“`
go to source

UIBarButtonItem+Extension

“`swift
extension UIBarButtonItem {
func setTitleColor(_ color: UIColor?, for: UIControl.State)
func setTitleFont(_ font: UIFont?, for: UIControl.State)
}
“`
go to source

UIGestureRecognizer+Extension

“`swift
extension UIGestureRecognizer {
typealias GestureAction = ((UIGestureRecognizer) -> Void)
func setAction(_ action: GestureAction?)
}
“`
go to source

UIAlertController+Extension

“`swift
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
}
“`
go to source

SensitiveButton

“`swift
class SensitiveButton: UIButton {
let hitTester = SensitiveHitTester()
}

class SensitiveHitTester: NSObject {
var extraHitEdgeInsets: UIEdgeInsets
func point(inside point: CGPoint, bounds: CGRect, with event: UIEvent?) -> Bool
}
“`
go to source

Author

zzangzio, [email protected]

License

CVSKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "CVSKit",
    "version": "0.4.0",
    "summary": "CVSKit is a collection of Swift extensions and utility.",
    "description": "CVSKit is a collection of Swift extensions and utility for better programming.",
    "homepage": "https://github.com/zzangzio/CVSKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "zzangzio": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.2",
    "requires_arc": true,
    "source": {
        "git": "https://github.com/zzangzio/CVSKit.git",
        "tag": "0.4.0"
    },
    "source_files": "Sources/**/*"
}

Pin It on Pinterest

Share This