Snowflake

public struct Snowflake

The stored type of a Discord Snowflake ID

  • The internal ID storage for a snowflake

    Declaration

    Swift

    public let rawValue: UInt64
  • Initialize from a UInt64

    Declaration

    Swift

    public init(_ snowflake: UInt64)
  • Initialize from a string

    Declaration

    Swift

    public init?(_ string: String)
  • Initialize from an optional string (returns nil if the input was nil or if it failed to initialize)

    Declaration

    Swift

    public init?(_ optionalString: String?)
  • Discord’s epoch

    Declaration

    Swift

    public static let epoch = Date(timeIntervalSince1970: 1420070400)
  • Time when snowflake was created

    Declaration

    Swift

    public var timestamp: Date
  • Discord’s internal worker ID that generated this snowflake

    Declaration

    Swift

    public var workerId: Int
  • Discord’s internal process under worker that generated this snowflake

    Declaration

    Swift

    public var processId: Int
  • Number of generated ID’s for the process

    Declaration

    Swift

    public var numberInProcess: Int
  • Creates a fake snowflake that would have been created at the specified date Useful for things like the messages before/after/around endpoint

    Declaration

    Swift

    public static func fakeSnowflake(date: Date) -> Snowflake?

    Parameters

    date

    The date to make a fake snowflake for

    Return Value

    A fake snowflake with the specified date, or nil if the specified date will not make a valid snowflake

  • Set this key to true on an encoder to encode Snowflakes as UInt64s instead of Strings. This will save space in binary encoders like binary plists, but will cause encoded JSON to be incompatible with Discord. Since JSON isn’t a binary encoding, it won’t save much space there anyways.

    Declaration

    Swift

    public static let encodeAsUInt64 = CodingUserInfoKey(rawValue: "snowflakeAsUInt64")!
  • Decodable implementation.

    Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Encodable implementation.

    Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • Declaration

    Swift

    public typealias IntegerLiteralType = UInt64
  • Initialize from an integer literal

    Declaration

    Swift

    public init(integerLiteral value: UInt64)
  • Description for string Conversion

    Declaration

    Swift

    public var description: String
  • Declaration

    Swift

    public typealias RawValue = UInt64
  • Init for rawValue conformance

    Declaration

    Swift

    public init(rawValue: UInt64)
  • Used to compare Snowflakes (which is useful because a greater Snowflake was made later)

    Declaration

    Swift

    public static func <(lhs: Snowflake, rhs: Snowflake) -> Bool
  • The hash value of the Snowflake

    Declaration

    Swift

    public var hashValue: Int