WWDC 2007 2008 2009 2010 2011 2012 2013 2014 2015
extension Collection { | |
func parallelMap<T>( | |
parallelism requestedParallelism: Int? = nil, | |
_ transform: @escaping (Element) async throws -> T | |
) async throws -> [T] { | |
let defaultParallelism = 2 | |
let parallelism = requestedParallelism ?? defaultParallelism | |
let n = self.count | |
if n == 0 { |
- Proposal: SE-NNNN
- Authors: Marc Rasi, Chris Lattner
- Review Manager: TBD
- Status: Awaiting implementation
Swift-evolution thread: https://forums.swift.org/t/pitch-compile-time-constant-expressions-for-swift/12879
- 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.
One of the goals of the concurrency effort is to prevent data races. This document describes the approach taken to preventing data races overall, by categorizing the sources of data races and describing how they are addressed with other proposals in the Swift Concurrency effort.
A data race occurs when two threads access the same memory concurrently and at least one of the accesses can change the value. Within the safe subset of Swift (e.g., ignoring the use of UnsafeMutablePointer
and related types), the memory in question is always a stored property. There are several different categories of stored properties that need to be considered for data races:
- Global and static stored properties:
@objc func _needsDoubleUpdateConstraintsPass() -> Bool { | |
return true | |
} | |
override var intrinsicContentSize: CGSize { | |
return attributedText?.size(forWidth: (engineBounds ?? bounds).width) ?? .zero | |
} | |
var engineBounds: CGRect? { | |
let objcSelector = "_nsis_compatibleBoundsInEngine:") |
Swift’s type system supports a number of different ways of taking a function or type and abstracting it. Usually, this is done by adding a generic parameter and an associated set of constraints. Similarly, a function that takes a particular type of argument can be abstracted to any number of those arguments by making it variadic with triple-dot (...) syntax. Today, both of these features are permitted separately: you can define a generic function that takes a variable number of arguments, such as
func debugPrint<T>(_ items: T...)
where T: CustomDebugStringConvertible
{
for (item: T) in items {
stdout.write(item.debugDescription)
[LLDB] can be customized with ~/.lldbinit
to run commands and to load more commands from
shell and python scripts. One option is [Chisel] which provides several commands which can
be used to debug an software running in Xcode.
It is critical that LLDB can process the commands in ~/.lldbinit
successfully as a failure
can cause the debugger to fail or run in an undefined way. The configuration listed in this Gist
prints a message at the start and end so that when the debugger is run it is clear if any errors
are shown in the Xcode console they are related to LLDB.
As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self
or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.
There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable
conformances, for ex