Hammer 1.3

Hammer 1.3

Igor Matyushkin 维护。




Hammer 1.3

Hammer

概览

Hammer是解决类和对象常见任务的有力工具。

如何开始

  • Source文件夹的内容复制到您的项目中。

  • 使用Hammer Cocoapod

要求

  • iOS 9及其以上版本
  • Xcode 9及其以上版本
  • Swift 4

用法

类名

获取类名

let classNameWithNamespace = MainViewController.hmr.fullName     // "MyApplication.MainViewController"
let classNameWithoutNamespace = MainViewController.hmr.shortName // "MainViewController"

对象转换

在外部闭包中使用对象

let label = UILabel().hmr.use { (label) in
            label.text = "This is a label"
}.object

在外部闭包中使用转换为其他类型的对象

let view = SomeView().hmr.use(as: UILabel.self) { (label) in
    label.text = "This is a label"
}.object

对象保留

保留任意对象

object.hmr.hold()

释放对象

object.hmr.free()

容器

任何对象都可以轻松地被特殊容器包装

let number: NSNumber? = nil

let container = number.hmr.wrap()
container.value // nil
container.isNil // true

仅限娱乐

您可以将任何对 hmr 的使用替换为锤子表情符号

let classNameWithNamespace = MainViewController.🔨.fullName
let classNameWithoutNamespace = MainViewController.🔨.shortName

let view = SomeView().🔨.use(as: UILabel.self) { (label) in
    label.text = "This is a label"
}.object

// etc.

许可

Hammer可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。