Swift 中的方法(函数)
来源:互联网 发布:开发一个刷赞软件 编辑:程序博客网 时间:2024/06/05 11:54
Swift 中的方法
- 方法其实就是定义在类中的函数, 在OC中,只可以在类中定义发方法,而在 Swift中,方法不仅可以定义在类,还可以定义在结构体、枚举中
- Swift 中的方法根据使用方式的不同可以分为 实例方法 和 类型方法
实例方法
代码示例
class Person { func play(str:String) -> Void { print("玩 \(str)") }}let p1 = Person()p1.play(str: "篮球")
类型方法
class Weather { class func winter() { print("春天来了") }}Weather.winter()
结构体中的类型方法
struct Stu { static func learn() { print("学习") }}Stu.learn()
枚举中的类型方法
enum Animal { static func run() { print("动物在跑") }}Animal.run()
阅读全文
0 0
- Swift 中的方法(函数)
- Swift中的标准函数
- Swift中的函数
- Swift中的floor()函数
- 9. Swift 中的函数
- Swift中的柯里化函数
- swift中的函数
- Swift 中的函数
- Swift-函数、方法
- Swift:函数与方法
- Swift中的构造方法
- swift AppDelegate中的方法
- swift中的类型方法
- Swift中的构造方法
- Swift 中的floor()函数 用途
- swift - 方法和全局函数
- Swift入门教程系列5-函数+selector在swift中的用法
- 【iOS】Swift中的函数、断言、枚举等
- 约束布局constraint-layout导入失败的解决方案
- HDU5867-Water problem
- pgsql 计算时间差的秒数
- Leetcode OJ 24 Swap Nodes in Pairs [Medium]
- Unity3D 关于模型变形技术代码实现
- Swift 中的方法(函数)
- python-7
- Ruby:字符串处理函数
- 新版Bintray-极简上传Library到JCenter
- 删除文本中行尾空格-linux
- CentOS 7 上安装 Redis 服务器的方法
- lintcode带最小值操作的栈
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'attribute'. One of '{"http:
- 南宁邀请赛和省赛总结