Author: Chris Lattner
// How to use CoreLocation to get your location Speed, Floor, timestamp, Course Direction, Altitude above sea level | |
//TODO: Step 1 #################################################################### | |
// First of all import "CoreLocation" | |
import CoreLocation | |
//TODO: Step 2 #################################################################### |
- Proposal: SE-XXXX
- Authors: Chris Lattner, Joe Groff
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.
// | |
// SpinlockTestTests.swift | |
// SpinlockTestTests | |
// | |
// Created by Peter Steinberger on 04/10/2016. | |
// Copyright © 2016 PSPDFKit GmbH. All rights reserved. | |
// | |
import XCTest |
import Foundation | |
public protocol Observer: Equatable { | |
associatedtype EventType | |
func listen(_ event: EventType) | |
} | |
public protocol Observable { | |
associatedtype ObserverType: Observer | |
associatedtype EventType |
Values of macros from TargetConditionals.h.
Xcode 7 / iOS 9.1, tvOS 9.0, watchOS 2.0, OS X 10.11 SDKs
Macro | 🖥 | 📱 | 📱sim | ⌚️ | ⌚️sim | 📺 | 📺sim |
---|---|---|---|---|---|---|---|
TARGET_OS_MAC |
1 | 1 | 1 | 1 | 1 | 1 | 1 |
TARGET_OS_IPHONE |
0 | 1 | 1 | 1 | 1 | 1 | 1 |
TARGET_OS_IOS |
0 | 1 | 1 | 0 | 0 | 0 | 0 |
TARGET_OS_WATCH |
0 | 0 | 0 | 1 | 1 | 0 | 0 |
Modern Cocoa development involves a lot of asynchronous programming using blocks and NSOperations. A lot of APIs are exposing blocks and they are more natural to write a lot of logic, so we'll only focus on block-based APIs.
Block-based APIs are hard to use when number of operations grows and dependencies between them become more complicated. In this paper I introduce asynchronous semantics and Promise type to Swift language (borrowing ideas from design of throw-try-catch and optionals). Functions can opt-in to become async, programmer can compose complex logic involving asynchronous operations while compiler produces necessary closures to implement that logic. This proposal does not propose new runtime model, nor "actors" or "coroutines".