Swift3.0 类型转换 示例
2017-03-14 19:27
323 查看
// // ViewController.swift // test_Swift3.0_type_casting // // Created by jeffasd on 17/3/14. // Copyright © 2017年 jeffasd. All rights reserved. // import UIKit class 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. } }
相关文章推荐
- Swift3.0之String转换成基本数据类型 Int CGFloat Double
- Swift 3.0中 UnsafePointer<T> 类型转换
- Swift3.0中文教程:19.类型转换
- Swift3.0 - 类型转换
- C#将数据转换为指定类型,支持对可空类型(Nullable类)转换方法示例
- The Swift Programming Language--语言指南--类型转换
- 精通Flex 3.0――14.1.2 ActionScript与Java数据类型的转换
- javascript类型转换示例
- Swift数据类型及数据类型转换
- sql使用cast进行数据类型转换示例
- struts2示例代码-自定义局部类型转换器和自定义全局类型转换器
- Free Pascal (Lazarus)版Android NDK的应用示例之:常用数据类型的转换
- 黑马程序员—Java语言基础(关键字、标识符、注释、常量与变量、进制、数据类型、类型转换、代码示例)
- Swift编程语言学习1.4——数值型字面量、数值类型转换
- biztalk中使用.net class类型的消息(三) -- net class类型消息转换为xml消息的示例
- js整数字符串转换为金额类型数据(示例代码)
- js整数字符串转换为金额类型数据(示例代码)
- java学习-JAVA基本排序法示例,JAVA数据类型转换 ,ArrayList用法,Calendar 简单应用
- Java语言基础(关键字、标识符、注释、常量与变量、进制、数据类型、类型转换、代码示例)
- 数据类型转换示例