mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-02-22 00:00:06 +08:00
Add Then implementation to the provider
This commit is contained in:
62
OpenVPN Tunnel Provider/Then.swift
Normal file
62
OpenVPN Tunnel Provider/Then.swift
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Then.swift
|
||||
// MCPEBot
|
||||
//
|
||||
// Created by Sergey Abramchuk on 27.01.17.
|
||||
// Copyright © 2017 ss-abramchuk. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
public protocol Then {}
|
||||
|
||||
extension Then where Self: Any {
|
||||
|
||||
/// Makes it available to set properties with closures just after initializing and copying the value types.
|
||||
///
|
||||
/// let frame = CGRect().with {
|
||||
/// $0.origin.x = 10
|
||||
/// $0.size.width = 100
|
||||
/// }
|
||||
public func with(_ block: (inout Self) -> Void) -> Self {
|
||||
var copy = self
|
||||
block(©)
|
||||
return copy
|
||||
}
|
||||
|
||||
/// Makes it available to execute something with closures.
|
||||
///
|
||||
/// UserDefaults.standard.do {
|
||||
/// $0.set("devxoul", forKey: "username")
|
||||
/// $0.set("devxoul@gmail.com", forKey: "email")
|
||||
/// $0.synchronize()
|
||||
/// }
|
||||
public func `do`(_ block: (Self) -> Void) {
|
||||
block(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Then where Self: AnyObject {
|
||||
|
||||
/// Makes it available to set properties with closures just after initializing.
|
||||
///
|
||||
/// let label = UILabel().then {
|
||||
/// $0.textAlignment = .Center
|
||||
/// $0.textColor = UIColor.blackColor()
|
||||
/// $0.text = "Hello, World!"
|
||||
/// }
|
||||
public func then(_ block: (Self) -> Void) -> Self {
|
||||
block(self)
|
||||
return self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension NSObject: Then {}
|
||||
|
||||
extension CGPoint: Then {}
|
||||
extension CGRect: Then {}
|
||||
extension CGSize: Then {}
|
||||
extension CGVector: Then {}
|
||||
Reference in New Issue
Block a user