Swift学习之方法
来源:互联网 发布:算法设计与分析陈慧南 编辑:程序博客网 时间:2024/05/24 00:34
Method :方法
1.实例方法
class Counter { var count = 0 func increment(){ ++count } func add(value:Int){ count += value } func reSet()->Int{ count = 0 return count }}let counter = Counter()counter.increment()print(counter.count) //1counter.add(3)print(counter.count) //4counter.reSet() //0struct Point { var x = 0.0 , y = 0.0 mutating func modifySelf(xValue:Double,withY yValue:Double){ self = Point(x: xValue, y: yValue) }}var point = Point(x: 2, y: 2)point.modifySelf(3, withY: 4)print(point.x) // 3.0
2.类型方法 :在func前面加static,用类型本身来调用该方法
class SomeClass { static func someFunc(){ print("This is a static fuc") }}SomeClass.someFunc() //"This is a static fuc"
0 0
- Swift学习之方法
- Swift语法学习之 方法
- swift简单学习之getter setter方法
- swift学习之set和get方法
- swift学习笔记之构造方法和析构方法
- 【swift】swift学习之旅!
- swift方法学习
- Swift学习:2.11 方法
- swift学习笔记之全局变量和全局方法
- swift学习笔记之setter和getter方法
- Swift 学习之路
- Swift学习之 泛型
- swift学习之数组
- swift学习之...和..<
- Swift学习之初识
- swift学习之杂乱无章
- Swift学习之 -- 函数
- Swift学习之UIButton
- ios开发常去的博客
- iOS--UINavigationBar使用总结
- csharp:Microsoft.Ink 手写识别(HandWriting Recognition)
- Swift学习之属性
- Retrofit+RxJava实战日志(1)-在Android Studio中配置
- Swift学习之方法
- C++使用cout补0
- “牛”是怎么死的
- springmvc 之 拦截器的实现(二)
- java160117StringTest
- Poj 2914 Minimum Cut
- java解析xml的几种方式
- Swift学习之下标
- Mac Apache 配置https(SSL/TLS)