Event

public struct Event

The Event struct represents an event dictionary in the REST API to a PredictionIO’s event server.

  • Reversed set event name.

    Declaration

    Swift

    public static let setEvent: String
  • Reversed unset event name.

    Declaration

    Swift

    public static let unsetEvent: String
  • Reversed delete event name.

    Declaration

    Swift

    public static let deleteEvent: String
  • Predefined user entity type.

    Declaration

    Swift

    public static let userEntityType: String
  • Predefined item entity type.

    Declaration

    Swift

    public static let itemEntityType: String
  • The event name e.g. sign-up, rate, view.

    Note: All event names starting with $ and pio_ are reversed and shouldn’t be used as your custom event (e.g. $set).

    Declaration

    Swift

    public let event: String
  • The entity type. It is the namespace of the entityID and analogous to the table name of a relational database. The entityID must be unique within the same entityType.

    Note: All entityType names starting with $ and pio_ are reversed and shouldn’t be used.

    Declaration

    Swift

    public let entityType: String
  • The entity ID. entityType-entityID becomes the unique identifier of the entity.

    Declaration

    Swift

    public let entityID: String
  • The target entity type.

    Note: All targetEntityType names starting with $ and pio_ are reversed and shouldn’t be used.

    Declaration

    Swift

    public let targetEntityType: String?
  • The target entity ID.

    Declaration

    Swift

    public let targetEntityID: String?
  • The event properties. It should be a valid JSON dictionary.

    Note: All properties names starting with $ and pio_ are reversed and shouldn’t be used.

    Declaration

    Swift

    public let properties: [String : Any]?
  • The time of the event.

    Declaration

    Swift

    public let eventTime: Date
  • The event ID. This value should only be set by the server.

    Declaration

    Swift

    public let eventID: String?
  • Creates an event struct.

    Declaration

    Swift

    public init(
        event: String,
        entityType: String,
        entityID: String,
        targetEntity: (type: String, id: String)? = nil,
        properties: [String: Any]? = nil,
        eventTime: Date = Date()
    )

    Parameters

    event

    The event name.

    entityType

    The entity type.

    entityID

    The entity ID.

    targetEntity

    The target entity (type, ID) tuple. nil by default.

    properties

    The event properties in JSON dictionary. nil by default.

    eventTime

    The event time. Current local time by default.

    Return Value

    The new Event instance.

  • Validates an event against the following rules:

    • properties must be a valid JSON dictionary.
    • An $unset event must not have an empty or nil properties.

    Declaration

    Swift

    public func validate() -> Error?

    Return Value

    A PIOError.invalidEvent error if the validation fails. Otherwise, returns nil.

  • Creates an event from a JSON dictionary.

    Throws

    A PIOError.failedDeserialization error if deserialization fails.

    Declaration

    Swift

    public init(json: [String : Any]) throws

    Return Value

    The new Event instance.

  • Returns a JSON dictionary representing the event.

    Declaration

    Swift

    public var json: [String : Any] { get }

    Return Value

    The JSON dictionary.