Swift3.0 类型转换 示例
来源:互联网 发布:淘宝开店怎么认证 编辑:程序博客网 时间:2024/06/05 14:36
//// ViewController.swift// test_Swift3.0_type_casting//// Created by jeffasd on 17/3/14.// Copyright © 2017年 jeffasd. All rights reserved.//import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { var obj: Any; obj = "hello world"; if obj is String { print("obj is String") } var things = [Any](); things.append(0); things.append(0.0) things.append(42) things.append(3.14) things.append("hello world") things.append( (3.0, 4.0) ) things.append({ (name: String) -> String in "hello, \(name)" }) for thing in things { print("the thing is \(thing)") switch thing { case 0 as Int: print("zero as an Int") case 0 as Double: print("zero as a Double") case let someInt as Int: print("an integer value of \(someInt)") case let someDouble as Double where someDouble > 0: print("a positive double value of \(someDouble)") case is Double: print("some other double value that I don't want to print") case let someString as String: print("a string value of \"\(someString)\"") case let (x, y) as (Double, Double): print("an (x, y) point at \(x), \(y)") case let stringConverter as (String) -> String: print(stringConverter("Michael")) default: print("something else") } } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}
0 0
- Swift3.0 类型转换 示例
- Swift3.0中文教程:19.类型转换
- Swift3.0- 类型转换、Any、AnyObject(可选链)
- Swift3.0 类型检查
- Swift3.0 类方法示例
- Swift3.0中文教程:4.集合类型
- Swift3.0中文教程:20.嵌套类型
- 十九 Swift3.0之 函数类型
- 三十三 Swift3.0之 可选类型
- Swift3.0中十六进制颜色转换UIColor
- Swift3.0中十六进制颜色转换UIColor
- c++常见类型转换示例
- 一些类型转换函数示例
- 九、swift3.0可选类型+类型修饰符及其它
- Swift3-集合类型
- swift3.0集合类型(Array,Set,Dictionary)
- Swift3.0 Optional String 类型 强制拆包
- swift3.0 学习 fileprivate lazy var 类型问题
- [Azure]使用Powershell重新生成ARM虚拟机网卡
- 《趣学Python编程》笔记---第一部分:学习编程(3)
- HashMap和TreeMap的区别
- Spring异步任务处理,@Async的配置和使用
- oracle数据库分区的几种方式
- Swift3.0 类型转换 示例
- mac 的家长控制
- 02-线性结构4 Pop Sequence
- Android 进程级别 和 oom_adj对应关系
- 第二周
- 大爱C++——单例模式
- C#中static void Main(string[] args) 参数详解
- hadoop之二维数据之kmeans深入
- 工作笔记:如何读源代码