Extensive Swift Utility Library Inspired By Python’s Standard Library

Last month I mentioned a utility library inspired by Underscore.js for Swift providing numerous helps for working with collections.

Here’s an open source library based on Python’s standard library providing numerous helpers for working with strings, numbers, and more called Pythonic.swift.

Here’s an example from the readme showing off some of the features of Pythonic.swift:

import Pythonic

if re.search("^foo", "foobar") {
  println(["foo", "bar", "zonk"].index("foo")) // 0
  println(["foo", "bar", "zonk"].count("bar")) // 1
  println(["foo", "bar", "zonk"].count("zoo")) // 0
}

if any(["foo", "bar", "zonk"]) {
  println(chr(ord("a"))) // a
}

var strings = ["foo", "bar"]
println(":".join(strings)) // foo:bar
if strings {
  println(strings[0]) // foo
}
if len(strings) == 2 {
  println(strings[1].upper()) // BAR
  println(strings[1].split("a")) // ["b", "r"]
}

var greeting = "   hello pythonista   "
if greeting.strip().startswith("hello") {
  println(greeting.strip().title()) // Hello Pythonista
}

var numbers = [1, 2, 3, 4, 5]
println(sum(numbers)) // 15
println(max(numbers)) // 5

You can find Pythonic.swift on Github here.

A nice python inspired addition to Swift.

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Extensive Swift Utility Library Inspired By Python’s Standard Library

©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *