Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using × as a custom operator for creating "x-by-y" values such as CGPoint or CGSize.
precedencegroup XByYPrecedence {
associativity: left
higherThan: MultiplicationPrecedence
}
infix operator ×: XByYPrecedence // U+00D7 MULTIPLICATION SIGN
// ------
import CoreGraphics
func × (x: CGFloat, y: CGFloat) -> CGPoint {
CGPoint(x: x, y: y)
}
func × (width: CGFloat, height: CGFloat) -> CGSize {
CGSize(width: width, height: height)
}
let point: CGPoint = 100×80
let size: CGSize = 800×600
// ------
import UIKit
let image = UIGraphicsImageRenderer(size: 320×240).image { context in
UIColor.yellow.setFill()
UIRectFill(CGRect(origin: 20×20, size: 280×200))
}
// ------
import SceneKit
func × (xy: CGPoint, z: CGFloat) -> SCNVector3 {
SCNVector3(xy.x, xy.y, z)
}
let point3D: SCNVector3 = 10×20×30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.