This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Sequence { | |
associatedtype Element | |
associatedtype Iterator : IteratorProtocol where Iterator.Element == Element | |
func makeIterator() -> Iterator | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
enum HTTPMethod: String { | |
case POST, GET | |
} | |
// An object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getProcessStartTime() -> TimeInterval { | |
let pid = ProcessInfo.processInfo.processIdentifier | |
var procInfo = kinfo_proc() | |
var cmd: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid] | |
var size = MemoryLayout.stride(ofValue: procInfo) | |
if sysctl(&cmd, UInt32(cmd.count), &procInfo, &size, nil, 0) == 0 { | |
// tv_sec is timestamp measured in second; tv_usec is the rest fraction part in microsecond | |
return Double(procInfo.kp_proc.p_un.__p_starttime.tv_sec) * 1000.0 + Double(procInfo.kp_proc.p_un.__p_starttime.tv_usec) / 1000.0 | |
} else { | |
print("Can't get information of process \(pid)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
enum HTTPMethod: String { | |
case POST, GET | |
} | |
// protocol of request, should define endpoint, http method, params and response type | |
protocol Request { | |
var path: String { get } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------------------------------------------*/ | |
#pragma mark - XCTAsserts | |
/*----------------------------------------------------*/ | |
XCTAssert(expression, format...); | |
XCTAssertTrue(expression, format...); | |
XCTAssertFalse(expression, format...); | |
XCTAssertEqual(expression1, expression2, format...); | |
XCTAssertNotEqual(expression1, expression2, format...); | |
XCTAssertNil(expression, format...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReactiveSwift | |
import Result | |
class MapViewController: UIViewController { | |
private let (didLoadSingal, didLoadObserver) = Signal<Bool, NoError>.pipe() | |
private let (didDragSignal, didDragObserver) = Signal<Bool, NoError>.pipe() | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MapViewController: UIViewController { | |
var isLoaded = false | |
} | |
extension MapViewController: MKMapViewDelegate { | |
func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) { | |
if isLoaded { | |
mapDidDrag() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://github.com/devxoul/Then/blob/master/Sources/Then/Then.swift | |
// It's easy to move them into your codebase | |
import Foundation | |
public protocol Then {} | |
extension Then where Self: Any { | |
/// Makes it available to set properties with closures just after initializing. | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
From: https://twitter.com/johnsundell/status/948513364015288320?utm_content=buffer67c28&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer | |
*/ | |
extension UIView { | |
func add(_ subviews: UIView...) { | |
subviews.forEach(addSubview) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Float { | |
var toInt32: Int32 { | |
// Directly bitwise copy and expressed as Int32 | |
return Int32(bitPattern: self.bitPattern) | |
} | |
} | |
lef f1 = Float(338_556) | |
let f2 = f1 + f1.ulp |