Get Updates By E-mail 

Article Written By:
Johann Dowa

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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments