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

Swift: The Basics的更多相关文章

  1. Swift 笔记汇总

    Swift 3 笔记 Swift: The Basics :介绍 Swift 一些零碎的点. Swift: Basic Operators :介绍 Swift 的操作符. Functions : 介绍 ...

  2. Swift中文手册 -- The Basics

    原文:Swift中文手册 -- The Basics 基础部分 Swift 是 iOS 和 OS X 应用开发的一门新语言.然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 S ...

  3. Swift -- 中文版两大官方文档汇总

    Swift官方文档由CocoaChina翻译小组精心翻译制作而成,目前两本文档中文版已全部完成!在此,我们对所有参与的译者.组织人员以及工作人员表示衷心的感谢!本文为您提供两本文档的在线阅读以及下载! ...

  4. An Introduction to Protocol Oriented Programming in Swift

    swift面向协议编程的根本原因在于值类型的存在:面向对象必须要有引用类型的支持: Protocol Oriented approach was introduced to resolve some ...

  5. Swift: Associated Types--为什么协议使用关联类型而不是泛型

    关联类型的形式为类型的引用进而进行约束提供了条件: 同时能够简化语法形式. Swift: Associated Types http://www.russbishop.net/swift-associ ...

  6. 随手记Swift基础和Optional Type(问号?和感叹号!)

    距离Apple推出Swift已经有几天了,网上也时不时出现"急招Swift程序猿,要求有一天工作经验"的帖子. 看到Swift,除了苹果放的另外一门语言的链接(http://swi ...

  7. swift的可选值(optional)

    苹果那文档写了一大堆也没有好好的写一下可选值(optional)这个东西.就是在有一个“Optional Chaining”的章节,但是也不是很充分的说明.最后找了半天在“the basics”里墨迹 ...

  8. 【读书笔记】The Swift Programming Language (Swift 4.0.3)

    素材:Language Guide 初次接触 Swift,建议先看下 A Swift Tour,否则思维转换会很费力,容易卡死或钻牛角尖. 同样是每一章只总结3个自己认为最重要的点.这样挺好!强迫你去 ...

  9. Basics

    [Basics] 1.You can declare multiple constants or multiple variables on a single line, separated by c ...

随机推荐

  1. phpcms栏目调用

    {loop subcat(0,0,0,$siteid) $r} {php $num++} <h3><a href="{$r[url]}">{$r[catna ...

  2. linux下搭建svn服务器

    安装步骤如下: 1.yum install subversion   2.输入rpm -ql subversion查看安装位置,如下图:   我们知道svn在bin目录下生成了几个二进制文件. 输入 ...

  3. asp.net mvc4 webapi Post 参数 字符串

    用  mvc4中的WEBAPI, Post 到后台的参数如果为string,则直接接收不到,解决方案有两种 1.传递参数为自定义类 2.通过如下方式获取: //获取传统context var cont ...

  4. hadoop 异常 datanode未启动

    暴力方法:(本人是学习阶段,实际工作中不能这么做)在各个节点上执行如下操作. 将/tmp 删除 将 conf/mapred-site.xml <property> <name> ...

  5. google 论文

    从google历年所有论文的汇总来看,TOP5的分别是人工智能和机器学习.算法理论.人机交互与视觉.自然语言处理.机器感知,大家从一个侧面看出goolge research的重点了吧. Google所 ...

  6. [BZOJ 2821] 作诗(Poetize) 【分块】

    题目链接:BZOJ - 2821 题目分析 因为强制在线了,所以无法用莫队..可以使用分块来做. 做法是,将 n 个数分成 n/x 个块,每个块大小为 x .先预处理出 f[i][j] ,表示从第 i ...

  7. mouseenter 和 mouseleave

    做一个下拉菜单的时候,HTML结构如下: <ul> <li class="red"> <a href="">第一级</ ...

  8. Unity3d IOS中的IGUI控件

    Unity3d IOS中的IGUI控件 @灰太龙  群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...

  9. Little Kings

    sgu223:http://acm.sgu.ru/problem.php?contest=0&problem=223 题意:n*n的格子放k个国王,一共有多少种放发. 题解:简单的状压DP. ...

  10. KVM如何以HADOOP作共享存储?

    看到西部数码的作法. 回想IBM的SMARTCLOUD作法,这主要就是应用了HDFS? 外加上HBASE和ZOOKEEPER保驾的? 然后,再想到,这HDFS和OPENSTATCK的SWIFT...纠 ...