一、数据类型

1、基础类型的封装

Swift provides its own versions of all fundamental C and Objective-C types, including Int for integers, Doubleand Float for floating-point values

2、新类型

Swift introduces advanced types not found in Objective-C, such as tuples.

Tuples enable you to create and pass around groupings of values.

3、类型安全语言

Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with.

4、数据类型转化

  1. let three = 3
  2. let pointOneFourOneFiveNine = 0.14159
  3. let pi = Double(three) + pointOneFourOneFiveNine
  4. // pi equals 3.14159, and is inferred to be of type Double

5、Tuples

  1. let http404Error = (404, "Not Found")
  1. let (statusCode, statusMessage) = http404Error
  2. print("The status code is \(statusCode)")
  3. // Prints "The status code is 404"
  4. print("The status message is \(statusMessage)")
  5. // Prints "The status message is Not Found"

6、Optionals

  1. let possibleNumber = "123"
  2. let convertedNumber = Int(possibleNumber)

  类型推断 convertedNumber:Int?

7、Optional Binding

  if let firstNumber = Int("4")

  You use optional binding to find out whether an optional contains a value

8、Implicitly Unwrapped Optionals

. You write an implicitly unwrapped optional by placing an exclamation mark (String!) rather than a question mark (String?) after the type that you want to make optional.

swift语言点评二的更多相关文章

  1. swift语言点评二十一-协议

    定义有什么,及哪些必须实现. A protocol defines a blueprint of methods, properties, and other requirements that su ...

  2. swift语言点评二十-扩展

    结论:扩展无法修改原来的数据结构. Extensions can add new functionality to a type, but they cannot override existing ...

  3. Swift语言指南(二)--语言基础之注释和分号

    原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...

  4. swift语言点评十二-Subscripts

    Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the m ...

  5. swift语言点评四-Closure

    总结:整个Closure的作用在于简化语言表述形式. 一.闭包的简化 Closure expression syntax has the following general form: { () -& ...

  6. swift语言点评一

    一.变量定义 1.常量与变量 Use let to make a constant and var to make a variable. 2.类型与推测 However, you don’t alw ...

  7. swift语言点评十九-类型转化与检查

    1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...

  8. swift语言点评十八-异常与错误

    1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...

  9. swift语言点评十七-Designated Initializers and Convenience Initializers

    Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...

随机推荐

  1. js获取浏览器中相关容器的高度

    网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: document.body.offset ...

  2. es6总结(二)

    1.es6三种声明方式: a.var 全局声明 b.let  局部变量声明 c.const     常量声明 2.变量的解构赋值 a.数组的解构赋值 等号左边与右边形式统一  let [a,[b,c] ...

  3. 自定义view 之多个引导层动画效果

    SupernatantView 如果我英文还可以的话这个应该叫做漂浮在上层的view---引导层 今天闲来无事看了网上的一些引导层案例总感觉如果不是很舒服,就是类似于很死板的显示和消失 我在想能不能弄 ...

  4. js 基本基础知识回顾

    js中的一切的变量.函数.操作符等等都是区分大小写的. js的基本的数据类型->包含下面的5种: 1.undefined 2.Null 3.Boolean 4.Number 5.String j ...

  5. Functional programming-函数式编程

    In computer science, functional programming is a programming paradigm—a style of building the struct ...

  6. protocol 和delegate(协议和代理)的区别

    定义 protocol:中文叫协议,一个只有方法体(没有具体实现)的类,Java中称作接口,实现协议的类必须实现协议中@required标记的方法(如果有的话): delegate:中文叫代理或委托, ...

  7. java简单实现MD5加密

    1.话不多说,直接上代码-----传入字符串,返回加密码 import java.security.MessageDigest; import java.text.NumberFormat; publ ...

  8. C# Windows Api的一些方法 封装 以及 常用参数

    using System;using System.Collections.Generic;using System.Drawing;using System.Diagnostics;using Sy ...

  9. 我的Linux系统开始学习的过程

    Linux系统,不知大家是否了解.接触计算机不多或对计算机不感冒的人可能对其比较陌生,曾经的我也是.上大学前的我的确对Linux一无所知,那时候接触面窄,都没有听说过此名字,上了大学后,身边的人有学习 ...

  10. 使用xpath进行熟悉href属性

    HTML文档 <html> <body> <a href="http://www.example.com">Example</a> ...