Skip to content

Instantly share code, notes, and snippets.

View dmsl1805's full-sized avatar
🏎️

Dmitriy Shulzhenko dmsl1805

🏎️
View GitHub Profile
fun drawRating(vote: Int): String {
if (vote >= 0 && vote <= 20) {
return "★☆☆☆☆"
}
else if (vote > 20 && vote <= 40) {
return "★★☆☆☆"
}
else if (vote > 40 && vote <= 60) {
return "★★★☆☆"
}
#if DEBUG
extension UIWindow {
class var key: UIWindow {
let selector: Selector = NSSelectorFromString("keyWindow")
let result = UIWindow.perform(selector)
return result?.takeUnretainedValue() as! UIWindow
}
}
//
// GradientView.swift
// Aura
//
// Created by Egor Sakhabaev on 23.07.17.
// Copyright © 2017 Egor Sakhabaev. All rights reserved.
//
import UIKit
@lattner
lattner / async_swift_proposal.md
Last active September 12, 2024 07:25 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

import Dispatch
public typealias Provider<E> = () -> E
class Container {
{% for type in types.all %}
{% if type|annotated:"singleton" %}
private let {{type.name|lowerFirstWord}}Queue = DispatchQueue(label: "singleton:{{type.name|lowerFirstWord}}")
private var __{{type.name|lowerFirstWord}}: {{type.name}}?