Swiftpack.co -  Swiftgram/TDLibFramework as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
TDLib for iOS, macOS, watchOS and tvOS packed in XCFramework and SPM.
.package(url: "https://github.com/Swiftgram/TDLibFramework.git", from: "1.7.6-9e7bce1")



Project contains pre-compiled TDLib binary for iOS, macOS, watchOS, tvOS and simulators in .xcframework bundle.

If you're looking for pure Swift library, check out TDLibKit



  1. Install Xcode 12.5+
  2. Add https://github.com/Swiftgram/TDLibFramework as SPM dependency in Project > Swift Packages. This could take a while cause it downloads ~300mb zip file with xcframework.
  3. Add arm64 to EXCLUDED_ARCHS due to lack of arm64 support or use ONLY_ACTIVE_ARCH=YES for debug builds on Intel CPU.
  4. Add TDLibFramework as your target dependency.
  5. Add libz.1.tbd and libc++.1.tbd as your target dependencies.
  6. If something is not accesible from TDLibFramework, make sure to add libSystem.B.tbd for all platforms and libc++abi.tbd if you're building non-macOS app. Source
  7. Code!


See Wiki page


Create client

let client: UnsafeMutableRawPointer! = td_json_client_create()

Make request object

let request = ["@type": "getTextEntities", "text": "@telegram /test_command https://telegram.org telegram.me", "@extra": ["5", 7.0, "\\u00e4"]] as [String: Any]

JSON Serialization and Deserialization

Small example for helper functions you will need to talk with TDLib

func dictToJSONString(_ dictionary: [String: Any]) -> String {
    let dictionaryData = try! JSONSerialization.data(withJSONObject: dictionary)
    return String(data: dictionaryData, encoding: .utf8)!

func JSONStringToDict(_ string: String) -> [String: Any] {
    let responseData = string.data(using: .utf8)!
    return try! JSONSerialization.jsonObject(with: responseData, options: .allowFragments) as! [String: Any]

Synchronious requests

Only for methods with "Can be called synchronously" in docs

if let res = td_json_client_execute(client, dictToJSONString(request)) {
    let responseString = String(cString: res)
    let responseDict = JSONStringToDict(responseString)
    print("Response from TDLib \(responseDict)")

Async requests

let request = ["@type": "setTdlibParameters",
                "parameters": [
                    "database_directory": "tdlib",
                    "use_message_database": true,
                    "use_secret_chats": true,
                    "api_id": 94575,
                    "api_hash": "a3406de8d171bb422bb6ddf3bbd800e2",
                    "system_language_code": "en",
                    "device_model": "Desktop",
                    "application_version": "1.0",
                    "enable_storage_optimizer": true
                ] as [String : Any]

// Send request
td_json_client_send(client, dictToJSONString(request))

// Block thread and wait for response (not more 5.0 seconds)
if let response = td_json_client_receive(client, 5.0) {
   let responseString = String(cString: res)
   let responseDict = JSONStringToDict(responseString)
   print("Async response from TDLib \(responseDict)")

Destroy client on exit



You can find latest releases at Releases page.

You can request tdlib version update with an Issue


You can find more about build process in Github Actions file.


  • ☐ Lib tests on watchOS simulator

M1 Support

Apple Silicon is not supported due to lack of Python 2 support in Python-Apple-Support (thus TDLib) can't be compiled natively on arm64 Macs.

If you want to build on M1, please run Xcode under Apple Rosetta 2

More info in this Telegram thread


  • Anton Glezman for Build Guide and basic implementation
  • Telegram Team for TDLib




Stars: 0
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes


XCFramework based on TDLib-1.7.6 commit 9e7bce1

ZIP Checksum 560953c2ff513cda03aaeeb6dd15659be8d682eab79e4771eeb692a18f663e30

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API