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 | |
} | |
// 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
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
protocol MyProcotol {} | |
struct MyStruct { | |
let x = 1 | |
let y = 2 | |
} | |
// What's the difference of following two? | |
let existentialContainer: MyProtocol = MyStruct() | |
let structInstance = MyStruct() |
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
struct ExistentialContainer { | |
var valueBuffer: (Int, Int, Int) | |
var vwt: UnsafePointer<ValueWitness> | |
var pwt: UnsafePointer<ProtocolWitness> | |
} | |
protocol Fooable { | |
func foo() | |
} |
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 | |
// Requests | |
enum HTTPMethod: String { | |
case POST, GET | |
} | |
// Define what a request is | |
protocol Request { |
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 Drawable { | |
func draw() | |
} | |
struct Point: Drawable { | |
var x: Int | |
var y: Int | |
func draw() { | |
print("Draw a point at (\(x), \(y))") |
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
struct ExistentialContainer { | |
var valueBuffer: (Int, Int, Int) | |
var vwt: UnsafePointer<ValueWitness> | |
var pwt: UnsafePointer<ProtocolWitness> | |
} | |
struct ProtocolWitness { | |
var descriptor: ProtocolConformanceDescriptor | |
var draw: FunctionRef | |
} |
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: | |
protocol Drawable { | |
func draw() | |
} | |
// To: | |
struct Drawing<Shape> { | |
var draw: (Shape) -> () | |
} |
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 | |
// MARK: Model | |
struct User: Decodable { | |
let id: Int | |
let name: String | |
} | |
let usersDecode: (Data) -> [User]? = { data in |