Skip to content

Instantly share code, notes, and snippets.

@dorentus
Last active October 12, 2015 01:58
Show Gist options
  • Save dorentus/ace9607b3c4663cb94b8 to your computer and use it in GitHub Desktop.
Save dorentus/ace9607b3c4663cb94b8 to your computer and use it in GitHub Desktop.
class BrokenPrinter {}
extension BrokenPrinter {
static let print: () -> () = {
Swift.print("Hello, World.")
return {}
}()
}

有一个class BrokenPrinter {},使用extension扩展它使支持这样的调用BrokenPrinter.print(),且满足:

  1. 第一次调用BrokenPrinter.print()的时候使用 Swift 的print()打印出字符串Hello, World.
  2. 之后每次调用BrokenPrinter.print(),都不再有任何打印。

额外要求:

  • 不要借助 Objective-C runtime
  • 不要使用 GCD
  • 不要借助外部变量
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment