Binary auto-parsing for Swift.

What's New

Swift.Binary 1.1.1


Build Status


Binary auto-parsing for Swift 3.2 and 4.


For using the Encoder and Decoder classes you just need to declare your swift classes where all the properties are @objc dynamic and the class MUST extend from NSObject. Other thing is that Obj-c representable objects may be optional, but non obj-c representable objects MUST be defined non optional. But the @objc dynamic diretive will obligate you to define it right.

Writing example:

Example of the implementation for converting objects to data.

import Swift_Binary // very important

class Employee: NSObject {
    @objc fileprivate(set) dynamic var name: String?
    @objc fileprivate(set) dynamic var age: Int = 0

class Boss: Employee {
    @objc fileprivate(set) dynamic var employees: [Employee]?

let employee1: Employee = Employee()
employee1.name = "John Apple Juice"
employee1.age = 35

let boss: Boss = Boss()
boss.name = "Steve James Apple Orange Juice"
boss.age = 65

let encoder = Encoder()
let binaryData: Data = try! encoder.encode(boss)

Parsing example:

Example of the implementation for converting data to objects. Obs: Using the same classes from above.

let binaryData: Data = // binary NSData

let decoder = Decoder()
let boss: Boss = try! decoder.decode(binaryData)

assert(boss.name == "Steve James Apple Orange Juice")
assert(boss.age == 65)
assert(boss.employees![0].name == "John Apple Juice")
assert(boss.employees![0].age == 35)

Any doubts, post an issue or create a pull request. Pull requests are welcome. Thanks.


  • Swift Tools 4.0.0
View More Packages from this Author


  • None
Last updated: Sun Nov 19 2023 08:58:54 GMT-1000 (Hawaii-Aleutian Standard Time)