swift语言点评二
一、数据类型
1、基础类型的封装
Swift provides its own versions of all fundamental C and Objective-C types, including Int
for integers, Double
and 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、数据类型转化
let three = 3
let pointOneFourOneFiveNine = 0.14159
let pi = Double(three) + pointOneFourOneFiveNine
// pi equals 3.14159, and is inferred to be of type Double
5、Tuples
let http404Error = (404, "Not Found")
let (statusCode, statusMessage) = http404Error
print("The status code is \(statusCode)")
// Prints "The status code is 404"
print("The status message is \(statusMessage)")
// Prints "The status message is Not Found"
6、Optionals
let possibleNumber = "123"
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语言点评二的更多相关文章
- swift语言点评二十一-协议
定义有什么,及哪些必须实现. A protocol defines a blueprint of methods, properties, and other requirements that su ...
- swift语言点评二十-扩展
结论:扩展无法修改原来的数据结构. Extensions can add new functionality to a type, but they cannot override existing ...
- Swift语言指南(二)--语言基础之注释和分号
原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...
- swift语言点评十二-Subscripts
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the m ...
- swift语言点评四-Closure
总结:整个Closure的作用在于简化语言表述形式. 一.闭包的简化 Closure expression syntax has the following general form: { () -& ...
- swift语言点评一
一.变量定义 1.常量与变量 Use let to make a constant and var to make a variable. 2.类型与推测 However, you don’t alw ...
- swift语言点评十九-类型转化与检查
1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...
- swift语言点评十八-异常与错误
1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...
- swift语言点评十七-Designated Initializers and Convenience Initializers
Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...
随机推荐
- usaco 最少找零
Description 约翰在镇上买了 T 元钱的东西,正在研究如何付钱.假设有 N 种钞票,第 i 种钞票的面值为 Vi,约翰身上带着这样的钞票 Ci 张.商店老板罗伯是个土豪,所有种类的钞票都有无 ...
- 读书笔记第三周 人月神话 刘鼎乾 PB16070837
读书笔记第三周:人月神话 这本书主要讲述了如何管理一个软件开发团队的问题,其中如何提高团队的效率可以说是本书的重点之一了.感觉这本书地中文版翻译得比较晦涩,很多表达比较模糊,看起来有些吃力,因此下 ...
- depth peeling实现半透明
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aH
- css 书写推荐顺序
1.位置属性(position, top, right, z-index, display, float等)2.大小(width, height, padding, margin)3.文字系列(fon ...
- 基于vue项目的js工具方法汇总
以下是个人过去一年在vue项目的开发过程中经常会用到的一些公共方法,在此进行汇总,方便以后及有需要的朋友查看~ let util = {}; /** * @description 日期格式化 * @p ...
- Hihocoder1458-Parentheses Matching(stack,vector)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a string of balanced parentheses output all the matchin ...
- jQuery $.ajax跨域-JSONP获取JSON数据(转载)
Asynchronous JavaScript and XML (Ajax ) 是驱动新一代 Web 站点(流行术语为 Web 2.0 站点)的关键技术.Ajax 允许在不干扰 Web 应用程序的显示 ...
- day06-1 与用户交互以及格式化输出
目录 Python的与用户交互 Python2的input和raw_input(了解) 格式化输出 占位符 format函数格式化字符串 f-string格式化(方便) Python的与用户交互 in ...
- hdu1542 矩形面积并(线段树+离散化+扫描线)
题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解 ...
- CefSharp获取页面Html代码的两种方式
CefSharp在NuGet的简介是“The CefSharp Chromium-based browser component”,机翻的意思就是“基于Cefsharp Chromium的浏览器组件” ...