5sw / table-print

Printing a dictionary as a table has never been easier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TablePrint

Table Print

TablePrint is a tool designed for developers.
It prints tables of dictionaries in the debugger console.

Join us on Slack

Contents

✍️ Description

TablePrint simply comes with only one function that takes a dictionary:

func printTable(_ content: [AnyHashable : Any?])

πŸ–₯ Examples

1. Book Details

You can throw in a dictionary with anything in it.

let book: [AnyHashable : Any?] = [
    "title": "The iPhone Developer's Cookbook",
    "author": "Erica Sadun",
    "publish_date": Date(timeIntervalSince1970: 1261094400),
    "price": 16.65
]
printTable(book)
+--------------+---------------------------------+
| Key          | Value                           |
+--------------+---------------------------------+
| publish_date | 2009-12-18 00:00:00 +0000       |
| author       | Erica Sadun                     |
| title        | The iPhone Developer's Cookbook |
| price        | 16.65                           |
+--------------+---------------------------------+

2. String Attributes

let stringAttributes: [NSAttributedStringKey : Any?] = [
    .foregroundColor : UIColor.red,
    .kern : 1,
    .link: URL(string: "https://apple.com/"),
]
printTable(stringAttributes)
+---------+----------------------------------+
| Key     | Value                            |
+---------+----------------------------------+
| NSLink  | https://apple.com/               |
| NSColor | UIExtendedSRGBColorSpace 1 0 0 1 |
| NSKern  | 1                                |
+---------+----------------------------------+

πŸ’» How to use

TablePrint is available on Cocoapods. Just put following line in your Podfile:

pod 'TablePrint'

⚠️ Requirements

  • Swift 4+
  • iOS 9+
  • macOS 10.10+
  • Xcode 9+

🐞 Known Issues

  • #2 The column width is currently not limited. Long lines result in ugly line breaks that break the whole UI of the table.
  • #1 Can't run on macOS command line tool.

πŸ’ͺ Contribute

Issues and pull requests are welcome.

About

Printing a dictionary as a table has never been easier

License:MIT License


Languages

Language:Swift 82.4%Language:Ruby 13.0%Language:Objective-C 4.6%