有一个class BrokenPrinter {}
,使用extension
扩展它使支持这样的调用BrokenPrinter.print()
,且满足:
- 第一次调用
BrokenPrinter.print()
的时候使用 Swift 的print()
打印出字符串Hello, World.
- 之后每次调用
BrokenPrinter.print()
,都不再有任何打印。
额外要求:
- 不要借助 Objective-C runtime
- 不要使用 GCD
- 不要借助外部变量
class BrokenPrinter {} | |
extension BrokenPrinter { | |
static let print: () -> () = { | |
Swift.print("Hello, World.") | |
return {} | |
}() | |
} |