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
// A URLSession extension that fetches data from a URL and decodes to some Decodable type. | |
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL) | |
// Note: this requires Swift 5.5. | |
extension URLSession { | |
func decode<T: Decodable>( | |
_ type: T.Type = T.self, | |
from url: URL, | |
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, | |
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData, | |
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate |
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
// | |
// Gasp – a quick clone of the watchOS Breathe UI, for Swift Over Coffee | |
// https://github.com/twostraws/SwiftOverCoffee | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State private var flowerOut = false | |
var body: some View { |
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
// | |
// FOR FOLKS STUMBLING ACROSS THIS LATER | |
// This is an example of code that allows us to create arrays by calling a function a fixed number of times. | |
// In my example below I'm just sending in 5 because I don't want to cloud the benchmark with generating | |
// a random number or similar, but with this change you can replace the 5 with `Int.random(in: 1...10)` to | |
// get an array of random numbers. | |
// | |
// HERE'S THE STDLIB ADDITION TO MAKE THIS WORK: | |
// @inlinable | |
// @_semantics("array.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
import Foundation | |
let sundelL = { (t: Int) in return -(~t) } | |
let sundeLl = { return sundelL(sundelL($0)) } | |
let sundEll = { return sundeLl(sundeLl($0)) } | |
let sunDell = { return sundEll(sundEll($0)) } | |
let suNdell = { return sunDell(sunDell($0)) } | |
let sUndell = { return suNdell(suNdell($0)) } | |
let Sundell = { return sUndell(sUndell($0)) } | |
let sundell = { (t: Int) -> Int in print(UnicodeScalar(t)!, terminator: ""); return 0 } |
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
// | |
// type-layout-fuzzer.swift | |
// Paul Hudson / @twostraws / www.hackingwithswift.com | |
// | |
// This is a Swift 4 port of Joe Groff's type-layout-fuzzer.py. | |
// I haven't attempted to Swiftify the code – it's pretty | |
// much a line-by-line port. | |
// | |
// License: public domain / CC0 / seriously, do whatever | |
// you want with it. |
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
// | |
// PokemonGoViewController.swift | |
// Totally Top Sekrit Pokémon Go Source Code | |
// | |
// Created by Niantic on 07/01/2016. | |
// Copyright © 2016 Niantic rights reserved. | |
// | |
import UIKit |
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
// | |
// loveWins(): a simple function that accepts a UIImage and | |
// returns the same image blended with the rainbow flag | |
// of the LGBT pride movement. | |
// | |
// This is released for pedagogical reasons (I've tried to make | |
// the code as easy to follow as possible!) but you're welcome | |
// to use it for any purpose – consider the code yours. | |
// | |
// If you're using Xcode 7 / Swift 2, you need to make a tiny |
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
// | |
// SimpleScrollingStack.swift | |
// A super-simple demo of a scrolling UIStackView in iOS 9 | |
// | |
// Created by Paul Hudson on 10/06/2015. | |
// Learn Swift at www.hackingwithswift.com | |
// @twostraws | |
// | |
import UIKit |