Profile Operations

Core Data Models

Profile Model (ProfileModel)

profile.id: String                         // Unique profile identifier
profile.name: String?                      // User's display name
profile.nickname: String?                  // User's nickname
profile.email: String?                     // User's email address
profile.gender: Gender?                    // User's gender
profile.birthDate: Kotlinx_datetimeInstant? // User's birth date
profile.country: ProfileCountry?           // User's country
profile.interests: [Interest]?             // User's interests
profile.phoneNumber: String?               // User's phone number
profile.phoneCountryCode: String?          // Phone country code

Profile Operations

Get Current User Profile

do {
    let profile = try await sdk.profile().getProfile()
    print("User: \(profile.name ?? "Unknown")")
} catch {
    print("Error fetching profile: \(error)")
}

Update Own Profile

do {
    // Get the current user's mutable profile
    let profile = try await sdk.profile().getOwn()

    // Create a date for birth date (January 1, 1990)
    let birthDate = Calendar.current.date(from: DateComponents(year: 1990, month: 1, day: 1))!
    let birthInstant = Kotlinx_datetimeInstant.companion.fromEpochMilliseconds(epochMilliseconds: Int64(birthDate.timeIntervalSince1970 * 1000))

    // Create Interest objects
    let teamInterest = Interest(
        id: "fb:t:123",
        source: InterestSource.football,
        favourite: false,
        type: Type.team
    )

    let playerInterest = Interest(
        id: "player456",
        source: InterestSource.football,
        favourite: false,
        type: Type.player
    )

    // Update profile using method chaining
    let updatedProfile = try await profile
        .setBirthDate(birthDate: birthInstant)
        .setGender(gender: Gender.male)
        .setName(name: "John Doe")
        .setNickname(nickname: "johndoe")
        .setEmail(email: "[email protected]")
        .setCountry(countryId: "US")
        .setPhoneCountryCode(phoneCountryCode: "+1")
        .addInterest(interest: teamInterest)
        .addInterest(interest: playerInterest)
        .update()

    print("Profile updated successfully")
} catch {
    print("Error updating profile: \(error)")
}

Get User Badges

do {
    let badges = try await sdk.profile().getBadges(userId: "user123")
    print("User has \(badges.data?.count ?? 0) badges")
} catch {
    print("Error fetching badges: \(error)")
}

Follow/Unfollow Users

do {
    // Follow a user
    let followRequest = RequestFollow(profileId: "user123")
    try await sdk.profile().followUser(requestFollow: followRequest)

    // Check follow status
    let followStatus = try await sdk.profile().checkFollowStatus(profileIds: ["user123"])
    print("Follow status: \(followStatus)")
} catch {
    print("Error with follow operations: \(error)")
}

Get Profile by ID

do {
    let profile = try await sdk.profile().getById(userId: "user123", disableCache: false)
    print("User: \(profile.name ?? "Unknown")")
} catch {
    print("Error fetching profile: \(error)")
}

Get Profiles by IDs

do {
    let userIds = ["user1", "user2", "user3"]
    let profiles = try await sdk.profile().getByIds(userIds: userIds, search: nil, disableCache: false)

    if let profileArray = profiles.data {
        print("Found \(profileArray.count) profiles")
    }
} catch {
    print("Error fetching profiles: \(error)")
}

Get Own Profile

do {
    let profile = try await sdk.profile().getOwn()
    print("My profile: \(profile.getInfo().name ?? "Unknown")")
} catch {
    print("Error fetching own profile: \(error)")
}

Get Own Badges

do {
    let badges = try await sdk.profile().getOwnBadges()
    print("My badges: \(badges.data?.count ?? 0)")
} catch {
    print("Error fetching own badges: \(error)")
}

Get Own Stats

do {
    let stats = try await sdk.profile().getOwnStats()
    print("My stats: \(stats.totalPredictions) predictions")
} catch {
    print("Error fetching own stats: \(error)")
}

Get User Stats

do {
    let stats = try await sdk.profile().getStats(userId: "user123", disableCache: false)
    print("User stats: \(stats.totalPredictions) predictions")
} catch {
    print("Error fetching user stats: \(error)")
}

Get Profile Countries

do {
    let countries = try await sdk.profile().getCountries(disableCache: false)
    print("Available countries: \(countries.data?.count ?? 0)")
} catch {
    print("Error fetching countries: \(error)")
}

Get Followers

do {
    let filters = MainCursorFilters(limit: 20, startAfter: nil)
    let followers = try await sdk.profile().getFollowers(filters: filters)

    if let followerArray = followers.data {
        print("Followers: \(followerArray.count)")
    }
} catch {
    print("Error fetching followers: \(error)")
}

Get Following

do {
    let filters = MainCursorFilters(limit: 20, startAfter: nil)
    let following = try await sdk.profile().getFollowing(filters: filters)

    if let followingArray = following.data {
        print("Following: \(followingArray.count)")
    }
} catch {
    print("Error fetching following: \(error)")
}