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 | |
struct CustomDate: Decodable { | |
let dateISO8601: Date | |
let dateISO8601Milliseconds: Date | |
} | |
let json = """ | |
{ | |
"dateISO8601": "2017-06-21T15:29:32Z", |
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
## Moved to https://github.com/fassko/random/blob/master/macOS-install.md |
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
// | |
// LogglyDestination.swift | |
// qminder-tv | |
// | |
// Created by Kristaps Grinbergs on 03/01/2018. | |
// Copyright © 2018 Qminder. All rights reserved. | |
// | |
import Foundation |
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
let logglyDestination = LogglyDestination(owner: self, identifier: "logglyDestination") | |
logglyDestination.logQueue = XCGLogger.logQueue | |
logglyDestination.showLogIdentifier = false | |
logglyDestination.showFunctionName = true | |
logglyDestination.showThreadName = true | |
logglyDestination.showLevel = true | |
logglyDestination.showFileName = true | |
logglyDestination.showLineNumber = true | |
logglyDestination.showDate = true | |
logglyDestination.outputLevel = .verbose |
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
/// Wind speed with direction | |
enum WindSpeed { | |
case north(Double) | |
case east(Double) | |
case south(Double) | |
case west(Double) | |
} | |
let direction = WindSpeed.north(3.6) |
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
#!/usr/bin/env bash | |
# Put this file in /usr/local/bin and then run chmod +x on it to make it executable | |
command=$1 | |
shift | |
case $command in | |
"init" ) | |
swift package init "$@" |
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 webSocketTask(with: URL) -> URLSessionWebSocketTask | |
func webSocketTask(with: URLRequest) -> URLSessionWebSocketTask | |
func webSocketTask(with: URL, protocols: [String]) -> URLSessionWebSocketTask |
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
let urlSession = URLSession(configuration: .default) | |
let webSocketTask = urlSession.webSocketTask(with: "wss://echo.websocket.org") | |
webSocketTask.resume() |
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
let message = URLSessionWebSocketTask.Message.string("Hello World”) | |
webSocketTask.send(message) { error in | |
if let error = error { | |
print("WebSocket couldn’t send message because: \(error)") | |
} | |
} |
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
webSocketTask.receive { result in | |
switch result { | |
case .failure(let error): | |
print("Error in receiving message: \(error)") | |
case .success(let message): | |
switch message { | |
case .string(let text): | |
print("Received string: \(text)") | |
case .data(let data): | |
print("Received data: \(data)") |
OlderNewer