The table is a helper function to print the table.
You can print the table bypassing the Any data!
[e.g., 1d array
, 2d array
, and dictionary
]
It inspired by javascript
console.table
.
I'm sure if you practice coding interviews, it helps you a lot. You don't need to struggle for checking results using a build-in print function!
import Table
//1D Array of String with Header
print(table: ["Good", "Very Good", "Happy", "Cool!"], header: ["Wed", "Thu", "Fri", "Sat"])
//1D Array of Int
print(table: [2, 94231, 241245125125])
//1D Array of Double
print(table: [2.0, 931, 214.24124])
//2D Array of String
print(table: [["1", "HELLOW"], ["2", "WOLLEH"]], header: ["Index", "Words"])
//2D Array of String, but Length is not equal!
print(table: [["1", "b2"], ["Hellow", "Great!"], ["sdjfklsjdfklsadf", "dsf", "1"]])
//2D Array of Int, but Length is not equal!
print(table: [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]])
//D.I.C.T.I.O.N.A.R.Y!!
print(table: ["1": 1, 2: "Hellow?", 1.2: 0, "I'm Table": [1, 2, 3, 2, 1]], header: ["key", "value"])
+----+---------+-----+-----+
|Wed |Thu |Fri |Sat |
+----+---------+-----+-----+
|Good|Very Good|Happy|Cool!|
+----+---------+-----+-----+
+-+-----+------------+
|2|94231|241245125125|
+-+-----+------------+
+---+-----+---------+
|2.0|931.0|214.24124|
+---+-----+---------+
+-----+------+
|Index|Words |
+-----+------+
|1 |HELLOW|
+-----+------+
|2 |WOLLEH|
+-----+------+
+----------------+------+-+
|1 |b2 | |
+----------------+------+-+
|Hellow |Great!| |
+----------------+------+-+
|sdjfklsjdfklsadf|dsf |1|
+----------------+------+-+
+-+-+-+--+
|1|2|3| |
+-+-+-+--+
|4|5|6| |
+-+-+-+--+
|7|8|9|10|
+-+-+-+--+
+---------+---------------+
|key |value |
+---------+---------------+
|2 |Hellow? |
+---------+---------------+
|I'm Table|[1, 2, 3, 2, 1]|
+---------+---------------+
|1.2 |0 |
+---------+---------------+
|1 |1 |
+---------+---------------+
The default distribution is fillProportionally
.
print(table: ["Good", "Very Good", "Happy", "Cool!"], header: ["Wed", "Thu", "Fri", "Sat"])
+----+---------+-----+-----+
|Wed |Thu |Fri |Sat |
+----+---------+-----+-----+
|Good|Very Good|Happy|Cool!|
+----+---------+-----+-----+
But It can be set by fillEqually
like below
print(
table: ["Good", "Very Good", "Happy", "Cool!"],
header: ["Wed", "Thu", "Fri", "Sat"],
distribution: .fillEqually
)
+---------+---------+---------+---------+
|Wed |Thu |Fri |Sat |
+---------+---------+---------+---------+
|Good |Very Good|Happy |Cool! |
+---------+---------+---------+---------+
The table is only supported SPM (Swift Package Management)
I built playgroundbook using nef
. You can check ./playgroundbook
folder.
Clean up generated files for building ✓
Creating swift playground structure (Table) ✓
Downloading dependencies...... ✓
• Table
Get modules from repositories...... ✓
• Table
Building Swift Playground... ✓
🙌 rendered Playground Book in './Table/playgroundbook/Table.playgroundbook'
Copy Table.playgroundbook
into your iCloud
folder like below and then open it on iPad
Playground App
You can use it on your iPad Playground 😎
I'm going to support more types!
Table Style
I'm going to add testCases for dictionary next time.
Contributions to the Table are welcomed and encouraged!
If you have any questions about Table
, please email me at [email protected]
link |
Stars: 80 |
Last commit: 44 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics