Created
May 22, 2019 13:40
-
-
Save pofat/80344edd533ac6b38a58eae6b54fc2c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: | |
protocol Drawable { | |
func draw() | |
} | |
// To: | |
struct Drawing<Shape> { | |
var draw: (Shape) -> () | |
} | |
// 用來畫實心點 | |
let solidPointDrawer = Drawing<CGPoint> { point in | |
print("draw solid point: (\(point.x), \(point.y))") | |
} | |
// 用來畫空心點 | |
let hollowPointDrawer = Drawing<CGPoint> { point in | |
print("draw hollow point: (\(point.x), \(point.y))") | |
} | |
let point = CGPoint(x: 1, y: 1) | |
solidPointDrawer.draw(point) // 畫實心點 | |
hollowPointDrawer.draw(point) // 畫空心點 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment