swift中的类型方法
来源:互联网 发布:js json对象 动态key 编辑:程序博客网 时间:2024/06/09 18:21
定义
Instance methods, as described above, are methods that are called on an instance of a particular type. You can also define methods that are called on the type itself. These kinds of methods are called type methods. You indicate type methods by writing the static keyword before the method’s func keyword. Classes may also use the class keyword to allow subclasses to override the superclass’s implementation of that method.
实例方法,正如上边提到的,是那些被实例调用的方法。你也可以定义一些类型自己调用的方法。这种方法被称作类方法。你可以表明是类方法,在方法前加上static关键字。类也可以应用class关键字允许子类重写父类的实现。
注意
在oc中,你仅仅可以为类定义类型方法。在swift中,你可以类型方法为所有的类,结构体和枚举。每种类型方法都显示的由类型来限定应用范围。
Within the body of a type method, the implicit self property refers to the type itself, rather than an instance of that type. This means that you can use self to disambiguate between type properties and type method parameters, just as you do for instance properties and instance method parameters.
在类型方法内部,隐式的self指的是类型自己而不是实例。这意味着你可以应用self来区分参数还是属性。
More generally, any unqualified method and property names that you use within the body of a type method will refer to other type-level methods and properties. A type method can call another type method with the other method’s name, without needing to prefix it with the type name. Similarly, type methods on structures and enumerations can access type properties by using the type property’s name without a type name prefix.
大多数情况下,在类方法内部你应用的方法和属性可以引用其他的方法和属性。结构体和枚举也具有同样的功能。
- swift中的类型方法
- Swift中的集合类型
- swift 中的 Selector 类型
- swift - 类型中的self
- Swift 中的类型属性
- swift类型方法
- Swift中的枚举类型(一)
- Swift中的Range<Int>类型
- Swift中的构造方法
- swift AppDelegate中的方法
- Swift 中的方法(函数)
- Swift中的构造方法
- Swift 中的值类型和引用类型
- Swift 中的引用类型与值类型
- [Swift]实例方法和类型方法
- Swift:实例方法和类型方法
- Swift 实例方法&类型方法(九)
- Swift 中的可选类型(Optional)
- linux 搭建git服务器
- Stringbuffer String builder String
- 网站收藏
- Java transient简介
- QT,其他类中计算出的结果如何在ui界面的控件中显示?
- swift中的类型方法
- 浏览器选项卡切换事件
- [angularJs]被$urlRouterProvider.otherwise坑的不要不要的
- SpringBoot学习
- 解决Fragment的切换状态不能保存的问题
- java系统高并发解决方案(转载)
- SpringMVC学习-->控制反转(IoC)与依赖注入(DI
- shell 命令
- 【上级笔试之一】数据输入