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 ...
随机推荐
- Win8 Windows Defender default behaviour
Problem Description ********************* Is it possible, to change the default behaviour when findi ...
- RabbitMQ基础学习笔记(C#代码示例)
一.定义: MQ是MessageQueue,消息队列的简称(是流行的开源消息队列系统,利用erlang语言开发).MQ是一种应用程序对应用程序的通信方法.应用程序通过读写入队和出队的消息来通信,无需专 ...
- 『转』Writing Well
这是前辈Julie Zhuo的最新关于写作的文章,昨天写下-进行总结和阅读思考 这是一篇关于提笔写作的文章,首发在The looking glass...前辈每周都会回答一个读者的问题耶--This ...
- RocketMQ学习笔记(10)----RocketMQ的Producer 事务消息使用
1. 事务消息原理图 RocketMQ除了支持普通消息,顺序消息之外,还支持了事务消息. 1. 什么是分布式事务? 分布式事务就是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同 ...
- Unity Android发布“Bundle Identifier has not been set up correctly”
原文:http://answers.unity3d.com/questions/162141/android-bundle-identifier-has-not-been-setup.html
- 怎样验证layer.prompt输入的值为数值型???
JS中使用isNaN()判断layer.prompt输入的值为数值型,代码如下: layer.prompt({ title: '设置比值', }, function(value, index, ele ...
- easyUI datagrid表头的合并
图列: js代码 function initConfigTable(param){ $("#mulConfigureTableBox").empty(); $("#mul ...
- JS[获取两个日期中所有的月份]
//------[获取两个日期中所有的月份中] function getMonthBetween(start,end){ var result = []; var s = start.split(&q ...
- 小试牛刀之sort()排序的实现
受大学室友的鼓动,我也打算利用公众平台来记录自己的前端知识积累,同时呢,自己总结的东西,总归会有局限性,希望小伙伴能给我指点迷津.知识就是一张巨大的网,作为一名摸不清头绪的入学者,唯一能做的事情就是吐 ...
- vue如何每次打开子组件弹窗都进行初始化
:visible.sync 与 v-if同时使用即可.