VCardHelper

final class VCardHelper

Builds a vCard 3.0 string from a User profile for contact sharing.

Only land-based fields are included (name, email, home city, Discord, bio, photo). Cruise-specific fields such as cabin number and dinner team are omitted.

  • Serializes a vCard 3.0 string for user.

    When includeDetails is false, only identity (username) is emitted — used for quarantined profiles and banned requesters. Empty optional fields are omitted. Cruise-specific fields (cabin number, dinner team, profile greeting) are never included.

    Support for 4.0 which includes PRONOUNS seems to be limited in clients. I only looked at the MacOS Contacts app and it didn’t bother reading it.

    Throws

    If user has no ID.

    Declaration

    Swift

    static func buildVCard(
    	from user: User,
    	includeDetails: Bool,
    	photoData: Data? = nil,
    	photoFileExtension: String? = nil
    ) throws -> String

    Parameters

    user

    The profile to export. Must have an ID.

    includeDetails

    If false, only username/UID/PRODID/REV are emitted.

    photoData

    Optional thumbnail bytes to embed as a PHOTO;ENCODING=b property.

    photoFileExtension

    File extension of photoData (e.g. "jpg", "png"), used for TYPE.

    Return Value

    A CRLF-delimited vCard 3.0 document.

  • Maps an image file extension to a vCard 3.0 PHOTO TYPE parameter.

    Declaration

    Swift

    static func photoType(fromFileExtension ext: String?) -> String

    Parameters

    ext

    A file extension such as "jpg" or "png". Case-insensitive.

    Return Value

    "PNG", "GIF", or "JPEG" (the default for unknown/nil extensions).

  • Returns value if it is non-nil and non-empty; otherwise nil.

    Declaration

    Swift

    private static func nonEmpty(_ value: String?) -> String?

    Parameters

    value

    An optional string from a profile field.

    Return Value

    The original string, or nil if missing or empty.

  • Builds the vCard NOTE body from pronouns and the user’s about text.

    Declaration

    Swift

    private static func noteText(from user: User) -> String?

    Parameters

    user

    The profile whose preferredPronoun and about fields to combine.

    Return Value

    A note string (pronouns first, then about, separated by a newline), or nil if both fields are empty.

  • Splits a freeform real name into given/family parts for the vCard N property.

    Uses the last space as the family-name boundary (e.g. "Jane Doe" → given "Jane", family "Doe"). A single-token name, or a missing realName, is treated as given name only.

    Declaration

    Swift

    private static func structuredName(realName: String?, formattedName: String) -> (given: String, family: String?)

    Parameters

    realName

    The user’s realName field, or nil when details are hidden / unset.

    formattedName

    Fallback given name when realName is nil (display name or username).

    Return Value

    A (given, family) pair. family is nil when it cannot be determined.