Skip to content

Comment on Swift Blogparent

Comments

You can add your own operator overloading of different number types to mitigate the casting required see: https://github.com/jquave/EasyCast

You can also add your own String extension for length and index character at in a String with:

    extension String {
        var length: Int { return countElements(self) }

        subscript (i: Int) -> String {
            return String(Array(self)[i])
        }
    }
Which will now let you use `.length` on strings, e.g:
    "Cat".length; //3
And get the character at index with:
    "Cat"[1]; //a
I've more useful extensions at: https://github.com/mythz/swift-linq-examples/blob/master/src...

Which enables LINQ-like querying in Swift: https://github.com/mythz/swift-linq-examples

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.