Sendable
A type whose values can safely be passed across concurrency domains by copying.
protocol Sendable
You can safely pass values of a sendable type from one concurrency domain to another — for example, you can pass a sendable value as the argument when calling an actor’s methods. All of the following can be marked as sendable:
Value types
Reference types with no mutable storage
Reference types that internally manage access to their state
Functions and closures (by marking them with
@Sendable
)
Although this protocol doesn’t have any required methods or properties, it does have semantic requirements that are enforced at compile time. These requirements are listed in the sections below. Conformance to Sendable
must be declared in the same file as the type’s declaration.
To declare conformance to Sendable
without any compiler enforcement, write @unchecked Sendable
. You are responsible for the correctness of unchecked sendable types, for example, by protecting all access to its state with a lock or a queue. Unchecked conformance to Sendable
also disables enforcement of the rule that conformance must be in the same file.
For information about the language-level concurrency model that Task
is part of, see Concurrency in The Swift Programming Language.
Sendable Structures and Enumerations
To satisfy the requirements of the Sendable
protocol, an enumeration or structure must have only sendable members and associated values. In some cases, structures and enumerations that satisfy the requirements implicitly conform to Sendable
:
Frozen structures and enumerations
Structures and enumerations that aren’t public and aren’t marked
@usableFromInline
.
Otherwise, you need to declare conformance to Sendable
explicitly.
Structures that have nonsendable stored properties and enumerations that have nonsendable associated values can be marked as @unchecked Sendable
, disabling compile-time correctness checks, after you manually verify that they satisfy the Sendable
protocol’s semantic requirements.
Sendable Actors
All actor types implicitly conform to Sendable
because actors ensure that all access to their mutable state is performed sequentially.
Sendable Classes
To satisfy the requirements of the Sendable
protocol, a class must:
Be marked
final
Contain only stored properties that are immutable and sendable
Have no superclass or have
NSObject
as the superclass
Classes marked with @MainActor
are implicitly sendable, because the main actor coordinates all access to its state. These classes can have stored properties that are mutable and nonsendable.
Classes that don’t meet the requirements above can be marked as @unchecked Sendable
, disabling compile-time correctness checks, after you manually verify that they satisfy the Sendable
protocol’s semantic requirements.
Sendable Functions and Closures
Instead of conforming to the Sendable
protocol, you mark sendable functions and closures with the @Sendable
attribute. Any values that the function or closure captures must be sendable. In addition, sendable closures must use only by-value captures, and the captured values must be of a sendable type.
In a context that expects a sendable closure, a closure that satisfies the requirements implicitly conforms to Sendable
— for example, in a call to Task.detached(priority:operation:)
.
You can explicitly mark a closure as sendable by writing @Sendable
as part of a type annotation, or by writing @Sendable
before the closure’s parameters — for example:
let sendableClosure = { @Sendable (number: Int) -> String in
if number > 12 {
return "More than a dozen."
} else {
return "Less than a dozen"
}
}
Sendable Tuples
To satisfy the requirements of the Sendable
protocol, all of the elements of the tuple must be sendable. Tuples that satisfy the requirements implicitly conform to Sendable
.
Sendable Metatypes
Metatypes such as Int.Type
implicitly conform to the Sendable
protocol.
Citizens in Swift
Subtypes
protocol CodingKey
A type that can be used as a key for encoding and decoding.
protocol DurationProtocol
A type that defines a duration for a given
InstantProtocol
type.protocol Error
A type representing an error value that can be thrown.
protocol InstantProtocol
protocol UnsafeSendable
A type whose values can safely be passed across concurrency domains by copying, but which disables some safety checking at the conformance site.
Available in _Concurrency
Subtypes
protocol Actor
Common protocol to which all actors conform.
protocol AnyActor
Common marker protocol providing a shared “base” for both (local)
Actor
and (potentially remote)DistributedActor
types.protocol Clock
A mechanism in which to measure time, and delay work until a given point in time.
protocol Executor
A service that can execute jobs.
protocol SerialExecutor
A service that executes jobs.
Available in Distributed
Subtypes
protocol DistributedActor
The such obtained actor system is then used to
resolve(id:using:)
the decodedID
.protocol DistributedActorSystem
A distributed actor system underpins and implements all functionality of distributed actors.
protocol DistributedActorSystemError
Error protocol to which errors thrown by any
DistributedActorSystem
should conform.
Available in _RegexParser
Subtypes
Available in Foundation
Subtypes
protocol CustomNSError
Describes an error type that specifically provides a domain, code, and user-info dictionary.
protocol LocalizedError
Describes an error that provides localized messages describing why an error occurred and provides more information about the error.
protocol RecoverableError
Describes an error that may be recoverable by presenting several potential recovery options to the user.
Extension in BSON
Subtypes
Extension in ConsoleKit
Subtypes
protocol ActivityBar
An
ActivityIndicatorType
that renders an activity bar on a single line.protocol ActivityIndicatorType
ActivityIndicatorType
s are responsible for drawing / rendering the currentActivityIndicatorState
to theConsole
.protocol AnyAsyncCommand
A type-erased
Command
.protocol AsyncCommand
A command that can be run through a
Console
.protocol AsyncCommandGroup
A group of named commands that can be run through a
Console
.protocol Console
Protocol for powering styled Console I/O.
protocol LoggerFragment
A fragment of a log message.
protocol TimestampSource
A protocol to allow mocking the timestamp for tests
Extension in AsyncSequenceValidation
Subtypes
Extension in X509
Subtypes
Extension in TraceableErrors
Subtypes
protocol NamedError
An error type that supports printing with a custom heading.
protocol TraceableError
A link in a propogated error.
Extension in Logging
Subtypes
protocol LogHandler
A
LogHandler
is an implementation of a logging backend.protocol _SwiftLogSendableLogHandler
Extension in CoreMetrics
Subtypes
protocol CounterHandler
A
CounterHandler
represents a backend implementation of aCounter
.protocol FloatingPointCounterHandler
A
FloatingPointCounterHandler
represents a backend implementation of aFloatingPointCounter
.protocol MeterHandler
A
MeterHandler
represents a backend implementation of aMeter
.protocol MetricsFactory
The
MetricsFactory
is the bridge between theMetricsSystem
and the metrics backend implementation.MetricsFactory
’s role is to initialize concrete implementations of the various metric types:protocol RecorderHandler
A
RecorderHandler
represents a backend implementation of aRecorder
.protocol TimerHandler
A
TimerHandler
represents a backend implementation of aTimer
.protocol _SwiftMetricsSendableProtocol
Extension in Durations
Subtypes
Extension in MongoDriver
Subtypes
protocol MongoCommand<Response>
A type that represents a MongoDB command. All public command types (and command protocols) ultimately inherit from this protocol.
protocol MongoFailpoint
protocol MongoImplicitSessionCommand<Response>
A type that can encode a MongoDB command that can be run as part of a session, which can be implicitly generated if the command is sent to a deployment at large.
protocol MongoIterableCommand<Element>
protocol MongoLoggingTarget
protocol MongoRetryableError
protocol MongoTransactableCommand<Response>
Extension in NIOCore
Subtypes
protocol Channel
A
Channel
is easiest thought of as a network socket. But it can be anything that is capable of I/O operations such as read, write, connect, and bind.protocol ChannelOption
A configuration option that can be set on a
Channel
to configure different behaviour.protocol EventLoop
An EventLoop processes IO / tasks in an endless loop for
Channel
s until it’s closed.protocol EventLoopGroup
Provides an endless stream of
EventLoop
s to use.protocol MulticastChannel
A
MulticastChannel
is aChannel
that supports IP multicast operations: that is, a channel that can join multicast groups.protocol NIOAsyncSequenceProducerBackPressureStrategy
A protocol for the back-pressure strategy of the
NIOAsyncSequenceProducer
.protocol NIOAsyncSequenceProducerDelegate
The delegate of
NIOAsyncSequenceProducer
.protocol NIOAsyncWriterSinkDelegate
The delegate of the
NIOAsyncWriter
. It is the consumer of the yielded writes to theNIOAsyncWriter
. Furthermore, the delegate gets informed when theNIOAsyncWriter
terminated.protocol NIOSerialEventLoopExecutor
A helper protocol that can be mixed in to a NIO
EventLoop
to provide an automatic conformance toSerialExecutor
.protocol RecvByteBufferAllocator
Allocates
ByteBuffer
s to be used to read bytes from aChannel
and records the number of the actual bytes that were used.protocol SocketOptionProvider
This protocol defines an object, most commonly a
Channel
, that supports setting and getting socket options (viasetsockopt
/getsockopt
or similar). It provides a strongly typed API that makes working with larger, less-common socket options easier than theChannelOption
API allows.protocol _NIOPreconcurrencySendable
Extension in NIOExtras
Subtypes
protocol NIOExtrasError
Base type for errors from NIOExtras
Extension in NIOHPACK
Subtypes
Extension in NIOHTTP2
Subtypes
protocol NIOHTTP2Error
The base protocol for all errors thrown by
NIOHTTP2
.
Extension in NIOSSL
Subtypes
protocol NIOSSLCustomPrivateKey
NIOSSLCustomPrivateKey
defines the interface of a custom, non-BoringSSL private key.
Extension in HTTPServer
Subtypes
protocol HTTPServerDelegate<Operation>
protocol HTTPServerOperation
A user-defined type for a server’s representation of an HTTP request.
protocol ServerAuthority
Extension in SymbolGraphParts
Subtypes
Extension in SymbolGraphLinker
Subtypes
Extension in UnidocLinker
Subtypes
Extension in GitHubAPI
Subtypes
protocol GitHubApplication<Credentials>
The essence of a GitHub application. Not to be confused with
GitHubApp
.protocol GitHubRateLimitError
Extension in UnidocDB
Subtypes
Extension in UnidocQueries
Subtypes
Extension in Vapor
Subtypes
protocol AbortError
Errors conforming to this protocol will always be displayed by Vapor to the end-user (even in production mode where most errors are silenced).
protocol AsyncAuthenticator
Helper for creating authentication middleware.
protocol AsyncBasicAuthenticator
Helper for creating authentication middleware using the Basic authorization header.
protocol AsyncBearerAuthenticator
Helper for creating authentication middleware using the Bearer authorization header.
protocol AsyncCredentialsAuthenticator
Helper for creating authentication middleware using request body contents.
protocol AsyncMiddleware
AsyncMiddleware
is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses.AsyncMiddleware
can choose to pass requests on to the nextAsyncMiddleware
in a chain, or they can short circuit and return a customResponse
if desired.protocol AsyncRequestAuthenticator
Help for creating authentication middleware based on
Request
.protocol AsyncResponder
protocol AsyncSessionAuthenticator
Helper for creating authentication middleware in conjunction with
SessionsMiddleware
.protocol AsyncSessionDriver
Capable of managing CRUD operations for
Session
s.protocol Authenticatable
Capable of being authenticated.
protocol Authenticator
Helper for creating authentication middleware.
protocol BasicAuthenticator
Helper for creating authentication middleware using the Basic authorization header.
protocol BearerAuthenticator
Helper for creating authentication middleware using the Bearer authorization header.
protocol BodyStreamWriter
protocol Client
protocol CredentialsAuthenticator
Helper for creating authentication middleware using request body contents.
protocol DebuggableError
Debuggable
provides an interface that allows a type to be more easily debugged in the case of an error.protocol LifecycleHandler
protocol Middleware
Middleware
is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses.Middleware
can choose to pass requests on to the nextMiddleware
in a chain, or they can short circuit and return a customResponse
if desired.protocol PasswordHasher
protocol RequestAuthenticator
Help for creating authentication middleware based on
Request
.protocol Responder
protocol SessionAuthenticatable
Models conforming to this protocol can have their authentication status cached using
SessionAuthenticator
.protocol SessionAuthenticator
Helper for creating authentication middleware in conjunction with
SessionsMiddleware
.protocol SessionDriver
Capable of managing CRUD operations for
Session
s.protocol ValidatorResult