This week, I published my first CocoaPods library named “Boonary”.

In GitHub,

This makes it easier for conversion between Swift’s Bool and Int.

Example usage:

let thisIs1: Int = true.binary
let thisIsTrue: Bool = 1.boolean

The Motivation for the Library

Sometimes you will need to convert 1 to true and 0 to false, especially when you get/post HTTP request with binary parameter like:

parameter["loggedIn"] = isLoggedIn ? 1 : 0
parameter["isPremiumUser"] = isPremium ? 1 : 0

But it may burden for you to write such a code in every necessary part.

It’s even risky because you will make mistake to put 0/1 in reverse or misunderstand the meaning of the flag. …


Tomohiro Imaizumi

iOS Programmer, my post are only English

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store