All Articles

Functions or Read-Only Properties in Swift?

I’m not sure which is better.  If it’s returning something that is directly tied to the class: a slice/dice of properties is already has, I’m leaning towards properties. Because of the many examples I feel like read-only properties are the way to do.  I’m not the only person [wondering](http://stackoverflow.com/questions/24035276/computed-read-only- property-vs-function-in-swift), so that’s validating.

Property:

extension String {
    var fullSentences: [String] {
        // stuff
    }
}

Function:

extension String {
    func fullSentences() -> [String] {
        // stuff
    }
}
Published 12 Jul 2014

Code. Comics. Crossfit
Tim Broder on Twitter