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
$
andpio_
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
entityIDand analogous to the table name of a relational database. TheentityIDmust be unique within the sameentityType.Note: All entityType names starting with
$
andpio_
are reversed and shouldn’t be used.Declaration
Swift
public let entityType: String -
The entity ID.
entityType-entityIDbecomes the unique identifier of the entity.Declaration
Swift
public let entityID: String -
The target entity type.
Note: All targetEntityType names starting with
$
andpio_
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
$
andpio_
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
eventThe event name.
entityTypeThe entity type.
entityIDThe entity ID.
targetEntityThe target entity (type, ID) tuple.
nilby default.propertiesThe event properties in JSON dictionary.
nilby default.eventTimeThe event time. Current local time by default.
Return Value
The new
Eventinstance.
-
Validates an event against the following rules:
propertiesmust be a valid JSON dictionary.An
$unsetevent must not have an empty or nilproperties.
Declaration
Swift
public func validate() -> Error?Return Value
A
PIOError.invalidEventerror if the validation fails. Otherwise, returns nil.
-
Creates an event from a JSON dictionary.
Throws
A
PIOError.failedDeserializationerror if deserialization fails.Declaration
Swift
public init(json: [String : Any]) throwsReturn 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.
View on GitHub
Install in Dash
Event Structure Reference