[swift-users] They had parens upon thars

Travis Griggs travisgriggs at gmail.com
Tue Aug 2 15:50:48 CDT 2016


Chapter 1:

Coming from a Smalltalk background, I was enjoying added all kinds of properties to basic number types, for example:

extension Double {
    var rounded:Double {
        return round(self)
    }
}

Chapter 2: 

I upgraded to XCode8Beta4 yesterday and firstly got to change all of UIColor.someColor() calls to UIColor.someColor accessors.

Secondly I got to scratch my head for a while regarding the cryptic compiler errors I was now getting from my Double.rounded extension. I finally found that FloatingPoint has added a rounded() method. Creating a conflict with my rounded property (I presume). So removed my extension and changed all of the accesses of rounded to be calls to rounded(), as well as change the rounded properties I had made for my own Angle and Duration enums for to rounded() methods for consistencies sake.

Chapter 3:

At this point, I felt a bit like a Sneetch (Dr Seuss). I was basically shuffling empty parens around my code base to make the new version happy.

I realize it can probably never be black and white, but is there at least some guidelines as to when a property ought to be a niladic method, and when a niladic method ought to be a property?


More information about the swift-users mailing list