10.5 Swift类方法
来源:互联网 发布:域名购买哪家网站靠谱 编辑:程序博客网 时间:2024/06/05 01:15
/**
类型方法
通过类名称来调用的方法,就像类型属性一样。
类方法对应的关键字是static(结构体和枚举) class(类)
类方法里面不存在self
*/
struct TypeMethods {
var p:Int = 0
staticvar sp: Int =0
func method() ->Void {
print("p=\(p), sp=\(TypeMethods.sp)")
}
staticfunc staticMethod () {
// 也就是不能这样子调用 self.p
// print("p=\(p)")
// 但是可以这样
print("sp==\(TypeMethods.sp)")
}
}
var tm =TypeMethods()
tm.method()
class TypeMethods1 {
var p:Int = 0
classvar sp: Int {
return10
}
func method() ->Void {
print("p=\(p), sp=\(TypeMethods.sp)")
}
classfunc staticMethod () {
// 也就是不能这样子调用 self.p
// print("p=\(p)")
// 但是可以这样
print("sp==\(TypeMethods.sp)")
}
}
var tm1 =TypeMethods1()
tm1.method()
- 10.5 Swift类方法
- Swift 重写类方法
- Swift类方法
- Swift 类方法和实例方法
- Swift方法
- [Swift]方法
- Swift 方法
- Swift-- 方法
- Swift 方法
- Swift方法
- Swift 方法
- Swift方法
- Swift-方法
- swift方法
- swift 方法
- Swift 方法
- Swift - AppDelegate.swift类中默认方法的介绍
- [Swift]Swift的初始化方法
- Ag中的ng-class的用法
- bzoj 4516: [Sdoi2016]生成魔咒 (后缀自动机)
- UITableViewCell 的backgroundColor不起作用的问题?
- maven-core:jar:2.0.8, org.apache.maven:maven-error-diagnostics:jar:2.0.8: Failure to find org.apache
- Linux报“xxx is not in the sudoers file.This incident will be reported” 错误解决方法
- 10.5 Swift类方法
- C语言实现二叉排序树的增删查操作
- 使用Freeline提高你的工作效率
- 10.6 Swift中subscripts基本语法
- excel生成首写字母
- JavaScript对象声明
- MT6580 使用外部PA出现无声、音量小或者无法调增益
- 配置NTP时间服务器
- Vmware给ubuntu添加新硬盘(转)