1. Swift是类型安全的语言;
  2. Swift introduces optional types, which handle the absence of a value. Optional say either "there is a value, and it equals x" or "there isn't a value at all".
  3. 类型注解
    var welcomeMessage: String
    var red, green, double: Double
  4. 类型别名(Type Alias)
    typealias AudioSample = UInt16
    
    var maxAmplitudeFound = AudioSample.min
  5. 元组(Tuples):元组内的值可以是不同类型的任何值。
    let http404Error = (, "Not Found")
    //http404Error的类型是(Int, String)

    分解(decompose)元组:可以使用下划线来忽略一些值

    let (statusCode, _) = http404Error
    print("The status code is \(status)")

    也可以使用下标来取出单个值:

     print("The status code is \(http404Error.0)")
    // Prints "The status code is 404"
    print("The status message is \(http404Error.1)")
    // Prints "The status message is Not Found"

    可以在定义元组的时候,给每个元素命名:

    let http200Status = (statusCode: , description: "OK")

    这个时候,可以这样获取每个元素的值:

    print("The status code is \(http200Status.statusCode)")
  6. Optional type
    let possibleNumber = ""
    let convertedNumber = Int(possibleNumber)
    //convertedNumber的类型是 Int?, 不是Int

    Swift的nil跟oc中的nil不同。In Objective-C, nil is a pointer to a nonexistent object. In Swift, nil is not a pointer -- it's the absence of a value of certain type. Optionals of any type can be set to nil, not just object types.
    forced unwrapping
    optional binding
    implicity unwrapped optionals

最新文章

  1. php libevent 扩展使用示例
  2. JAVA程序操作hbase的Maven配置pom.xml文件
  3. SharpDevelop学习笔记(5)—— AddIns系统详解
  4. JSON学习之二
  5. 获取dom元素的宽度和高度
  6. navicat内的主键和外键
  7. Creating Help Pages for ASP.NET Web API -摘自网络
  8. Contiki学习入门之概览
  9. TDirectory.GetCreationTime、TDirectory.SetCreationTime获取和设置文件夹创建时间
  10. 如何让旧版IE浏览器认识HTML5元素
  11. iOS截取http/https流量
  12. Vue.js父与子组件之间传参
  13. 游戏行业DDoS攻击解决方案
  14. mysql悲观锁
  15. Hadoop生态圈-离线方式部署Cloudera Manager5.15.1
  16. learning scala read from file
  17. python打包--pyinstaller打包报错
  18. 在Asp.net core中使用WebScocket
  19. iOS presentedViewController和presentingViewController的区别
  20. Delete触发器

热门文章

  1. 关于js中alert弹出窗口换行!
  2. 那些年被我坑过的Python——玄而又玄(第六章 面向对象编程基础)
  3. [r]Setting up Django and your web server with uWSGI and nginx
  4. KVO初探
  5. 用硬件(Verilog)实现二进制码和格雷码的转换
  6. 转载:.NET Web开发技术简单整理
  7. C# WinForm的SplitContainer控件固定Panel大小[转]
  8. ALTER TABLE
  9. c#获取带有汉字的字符串长度
  10. Unity笔记