Latest 1.4.0
License MIT
Platforms ios 8.0, osx 10.10

Bencode is a general purpose bencode encoder & decoder written in swift 4.

Inspired by VFK SwiftyBencode & arvidsigvardsson/Bencode


⚠️ Xcode 9 is required ⚠️

Bencode is available through CocoaPods.
To install it, simply add the following line to your Podfile:

pod 'Bencode'


Initialize with URL:

let bencode: Bencode? = Bencode(file: torrentUrl)

Initialize with bencoded string:

let bencode: Bencode? = Bencode(bencodedString: content)

Accessing properties:

Accessing properties is very handy with subscripts & accessors.
Value accessors .int, .string, .list & .dict are optional.
Subscripts produces BencodeOptional enums, by doing so you can chain optional subscripts without having to write ? or ! behind every one of them.
Bencode also comfort to Sequence protocol, so you can use map, filter, foreach etc. on them. :)

let bencode = Bencode(file: torrentUrl)

let info = bencode["info"]
let files = info["files"]

// You can use them as a sequence
// .values is a shorthand for .map{ $0.value }
files.values.forEach {

// Easy optional chaning without unwapping every stage:
let filePath: String? = info["files"][0]["path"][0].string
let fileLength: Int? = bencode["info"]["files"]["length"].int


  • Post any issues you find
  • Post new feature requests
  • Pull requests are welcome


danieltmbr, [email protected]


Bencode is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "Bencode",
    "version": "1.4.0",
    "summary": "Pure swift Bencode decoder & encoder",
    "description": "This pod is a general purpose Bencode encoder & decoder.nCan be used for e.g.: decoding .torrent files.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "danieltmbr": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.4.0"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    "source_files": "Source/*.swift",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This