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
includeDetailsis 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
PRONOUNSseems to be limited in clients. I only looked at the MacOS Contacts app and it didn’t bother reading it.Throws
Ifuserhas no ID.Declaration
Swift
static func buildVCard( from user: User, includeDetails: Bool, photoData: Data? = nil, photoFileExtension: String? = nil ) throws -> StringParameters
userThe profile to export. Must have an ID.
includeDetailsIf false, only username/UID/PRODID/REV are emitted.
photoDataOptional thumbnail bytes to embed as a
PHOTO;ENCODING=bproperty.photoFileExtensionFile extension of
photoData(e.g."jpg","png"), used forTYPE.Return Value
A CRLF-delimited vCard 3.0 document.
-
Maps an image file extension to a vCard 3.0
PHOTOTYPE parameter.Declaration
Swift
static func photoType(fromFileExtension ext: String?) -> StringParameters
extA file extension such as
"jpg"or"png". Case-insensitive.Return Value
"PNG","GIF", or"JPEG"(the default for unknown/nil extensions). -
Returns
valueif it is non-nil and non-empty; otherwisenil.Declaration
Swift
private static func nonEmpty(_ value: String?) -> String?Parameters
valueAn optional string from a profile field.
Return Value
The original string, or
nilif missing or empty. -
Builds the vCard
NOTEbody from pronouns and the user’s about text.Declaration
Swift
private static func noteText(from user: User) -> String?Parameters
userThe profile whose
preferredPronounandaboutfields to combine.Return Value
A note string (pronouns first, then about, separated by a newline), or
nilif both fields are empty. -
Splits a freeform real name into given/family parts for the vCard
Nproperty.Uses the last space as the family-name boundary (e.g.
"Jane Doe"→ given"Jane", family"Doe"). A single-token name, or a missingrealName, is treated as given name only.Declaration
Swift
private static func structuredName(realName: String?, formattedName: String) -> (given: String, family: String?)Parameters
realNameThe user’s
realNamefield, ornilwhen details are hidden / unset.formattedNameFallback given name when
realNameis nil (display name or username).Return Value
A
(given, family)pair.familyisnilwhen it cannot be determined.
View on GitHub