Best Practices

1. SDK Initialization

  • Initialize the SDK once in your app's lifecycle (AppDelegate or App struct)
  • Store the SDK instance for reuse throughout the app
  • Handle initialization errors gracefully

2. Memory Management

  • Use [weak self] in completion handlers to avoid retain cycles
  • Properly manage SDK instances and avoid creating multiple instances

3. Threading

  • Always update UI on the main thread
  • SDK callbacks may come on background threads
  • Use DispatchQueue.main.async for UI updates

4. Caching

  • Use the disableCache parameter appropriately
  • Enable caching for frequently accessed data
  • Disable caching for real-time data

5. Error Handling

  • Always handle errors in completion handlers
  • Provide user-friendly error messages
  • Implement retry mechanisms for network failures

6. Performance

  • Use filters to limit data requests
  • Implement pagination for large datasets
  • Cache responses when appropriate

Key Implementation Patterns

Authentication Provider

class AuthProvider: IFUSDKTokenProvider {
    func getToken() async throws -> String? {
        // Implement your authentication logic
        // Return JWT token or similar
    }

    func logout() async throws {
        // Handle logout cleanup
    }
}

SDK Configuration

let config = FUSDKConfig(
    apiKey: "your-api-key",
    clientId: "your-client-id",
    lang: "en",
    idSchema: IDSchema.sportal365,
    environment: "prod",
    authProvider: AuthProvider()
)

let sdk = FansUnitedSDK.Companion.shared.doInit(config: config)

Data Fetching Pattern

// Create filters
let filters = MatchFilters(
    countryIds: nil,
    competitionIds: nil,
    matchIds: nil,
    status: nil,
    teamIds: nil,
    fromDate: todayInstant,
    toDate: nil,
    limit: 50,
    page: nil,
    sortField: nil,
    sortOrder: nil
)

// Fetch data directly from SDK
let matches = try await sdk.football().getMatches(filters: filters, disableCache: false)?.data