Suppose I want a property to tell me whether an arbitrary number is an integer. If the number is a Double, I can just use this:
extension Double {
var isInteger: Bool {
return Double(self) == Double(Int(self))
}
}
Of course I can make the same extension for CGFloat, or just cast a CGFloat to a Double. That's easy enough, but I'm curious: Is there a way of defining a function that will work for both Double and CGFloat without a cast? I've been working my way through the Protocols chapter of The Swift Programming Language and I'm wondering if there's a way of doing it with a protocol.