Skip to content

Instantly share code, notes, and snippets.

{{name}}

[![Swift][swift-badge]][swift-url] [![Zewo][zewo-badge]][zewo-url] [![Platform][platform-badge]][platform-url] [![License][mit-badge]][mit-url] [![Slack][slack-badge]][slack-url]

Installation

public protocol Error: ErrorProtocol {
var status: Status { get }
}
public enum ClientError: Error {
case badRequest
case unauthorized
case paymentRequired
case forbidden
case notFound
do {
let ip = try IP(localAddress: "127.0.0.1", port: 8080)
let serverSocket = try TCPServerSocket(ip: ip)
serverSocket.accept { getClientStream in
do {
let clientStream = try getClientStream()
clientStream.receive(length: Int.max) { getData in
do {
let data = try getData()
public typealias Byte = UInt8
public struct Data {
public var bytes: [Byte]
public init(_ bytes: [Byte]) {
self.bytes = bytes
}
}
@paulofaria
paulofaria / Package.swift
Last active March 18, 2016 22:52
Alias for packages
import PackageDescription
let package = Package(
name: "S4",
dependencies: [
.Package(url: "https://github.com/swiftx/http.git", majorVersion: 0, minor: 1, alias: "SwiftXHTTP"),
.Package(url: "https://github.com/Zewo/HTTP.git", majorVersion: 0, minor: 1, alias: "ZewoHTTP")
]
)
import Dispatch
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func delay(duration: Double, closure: Void -> Void) {
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(), closure)
}

S4 - Server Side Swift Standards

Byte

The Byte type represents a byte.

public typealias Byte = UInt8
let todoResources = Resource(middleware: recovery, contentNegotiaton) { todo in
todo.index { _ in
let todos = try app.getAllTodos()
return Response(content: ["todos": todos.content])
}
todo.create(mappingTo: Todo.self) { request, todo in
let todo = try app.createTodo(todo)
return Response(content: todo)
}
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"