young
(rtSwift)
1
var x = 1.0
let s = 0.5
x.scale(by: s)
print("x = \(x)")
swiftc scale.swift
scale.swift:3:3: error: value of type 'Double' has no member 'scale'
But .scale(by:) is documented here: https://developer.apple.com/documentation/swift/double/3299111-scale

cukr
2
There's " Framework SwiftUI" in the column on the right. What happens if you import SwiftUI?
1 Like
beepluis
(Luis Padron)
3
As @cukr mentioned, the scale(by:) method is an extension on Double which is only available in SwiftUI.
1 Like
young
(rtSwift)
4
Thanks! I need to remind myself things can be added by anything in Swift and look for its implementation source.
I was just trying to verify what .scale(by:) is just multiply, and it appears to be the case. Wonder what's the rationale for adding this, instead of simply just do x *= s. Maybe just to satisfy some mathematician's notion of what multiply mean?
scanon
(Steve Canon)
5
Maybe just to satisfy some mathematician's notion of what multiply mean?
Just the opposite! 
It comes from the VectorArithmetic protocol in SwiftUI; if it were just a concrete method on Double, they would use *=, but there are some drawbacks to following that approach with more general types (mostly around limitations of the current type inference system).
3 Likes
young
(rtSwift)
6
Make perfect sense now. Scale is correct for vector math.
Just realize, I shouldn't be using Double.scale(by:) in my code, because I'm not doing VectorArithmetic.