Vapor Documentation Beta

Structure Session​Data

public struct SessionData 

A container for storing data associated with a given SessionID.

You can add data to an instance of SessionData by subscripting:

let data = SessionData()
data["login_date"] = "\(Date())"

If you need a snapshot of the data stored in the container, such as for custom serialization to storage drivers, you can get a copy with .snapshot.

let data: SessionData = ["name": "Vapor"]
// creates a copy of the data as of this point
let snapshot = data.snapshot
client.storeUsingDictionary(snapshot)
%3 SessionData SessionData ExpressibleByDictionaryLiteral ExpressibleByDictionaryLiteral SessionData->ExpressibleByDictionaryLiteral Codable Codable SessionData->Codable

Conforms To

Codable
ExpressibleByDictionaryLiteral

Initializers

init()

public init() 

Creates a new empty session data container.

init(initial​Data:​)

public init(initialData data: [String: String]) 

Creates a session data container for the given data.

Parameters

data [String:​ String]

The data to store in the container.

init(from:​)

public init(from decoder: Decoder) throws 

init(dictionary​Literal:​)

public init(dictionaryLiteral elements: (String, String)...) 

init(_:​)

@available(*, deprecated, message: "use SessionData.init(initialData:)")
    public init(_ data: [String: String]) 

Properties

snapshot

public var snapshot: [String: String] 

A copy of the current data in the container.

Methods

==(lhs:​rhs:​)

public static func ==(lhs: SessionData, rhs: SessionData) -> Bool 

encode(to:​)

public func encode(to encoder: Encoder) throws