Identity

@objc(SFIdentity)
public final class Identity : NSObject

Main class for managing identity information in the Salesforce Marketing Cloud SDK.

The Identity class provides a singleton interface for managing user identity data, including profile information, custom attributes, and party identification details. All operations are performed thread-safely using an internal worker queue.

  • Converts the current identity information to a JSON string representation.

    Declaration

    Swift

    @objc
    public func toJson() -> String
  • Updates the identity information using a modifier closure.

    This method provides thread-safe access to modify identity data. The updater closure receives an IdentityModifier object that allows you to modify profile ID, attributes, and party identification information. All modifications are persisted to the database and trigger identity change events.

    Thread Safety:

    This method is thread-safe and uses an internal worker queue to ensure that identity modifications don’t interfere with other operations.

    Persistence:

    All changes made through this method are automatically persisted to the database and will trigger identity change events that other SDK modules can observe.

    Declaration

    Swift

    public func edit(identity updater: @escaping (IdentityModifier) -> IdentityModifier)

    Parameters

    updater

    A closure that receives an IdentityModifier and returns the modified IdentityModifier with the desired changes. The closure is executed synchronously on a background worker queue.

  • Retrieves the current identity information.

    This method returns the current identity data including profile ID, attributes, and party identification information. The data is retrieved from the in-memory cache for optimal performance.

    Thread Safety:

    This method is thread-safe and uses an internal worker queue to ensure consistent data access.

    Performance:

    This method retrieves data from the in-memory cache, making it very fast. If no identity has been set, it returns nil.

    Declaration

    Swift

    public func get() -> IdentityInfo?

    Return Value

    An IdentityInfo object containing the current identity data, or nil if no identity record is found or if the identity manager is not properly initialized.