Skip to content

Instantly share code, notes, and snippets.

View samdods's full-sized avatar

Sam Dods samdods

  • The App Business
  • London
View GitHub Profile
@samdods
samdods / SwiftServer-Loop.swift
Last active April 10, 2019 11:40
Listening on a socket and waiting for request
while(true) {
// 5: Wait for a request
let fd = accept(sock, nil, nil)
print("Connection made")
guard fd >= 0 else {
print("Can't accept connection")
@samdods
samdods / SwiftServer-Setup.swift
Last active April 10, 2019 07:50
Annotated Swift Server
// 1. Create a socket reference
let sock = socket(AF_INET, SOCK_STREAM, 0) // or use AF_INET6 for IPv6
guard sock >= 0 else {
fatalError("Failed to open socket")
}
// 2. Set socket options
// (SO_REUSEADDR allows reusing the port if server was shutdown while port active)
{
"case_studies": [
{
"client": "TfL",
"teaser": "Testing Tube brakes, with TfL Decelerator",
"vertical": "Public Sector",
"is_enterprise": true,
"title": "A World-First For Apple iPad",
"hero_image": "https://az759258.vo.msecnd.net/media/2221/decelerator_header-image-2x.jpg",
"sections": [
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath) as? ProductCell else {
// unlikely to happen, but better safe than sorry!
assertionFailure("Unable to dequeue cell")
return UITableViewCell()
}
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath) as! ProductCell
// use cell as non-optional
import XCTest
@testable import Recipeasy
class ExampleTests: XCTestCase {
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
class HomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
/*
// MARK: - Navigation
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}
// the first person whose street address is empty
people.first(where: ~\.address.street.isEmpty)
// => Returns the Person object for "Dick"
extension Bool {
/// Returns true for false and false for true
var inverted: Bool {
return !self
}
}
// only people with non-empty street
people.filter(~\.address.street.isEmpty.inverted)