swift类型操作规范
type(of:)
Applied to an object: the polymorphic (internal) type of the object, regardless of how a reference is typed. Static/class members are accessible by passing an object to type(of:).
.Type
Sent to a type in a type declaration: the polymorphic type. For example, in a function parameter declaration, Dog means a Dog instance is expected (or an instance of one its subclasses), but Dog.Type means that the Dog type itself is expected (or the type of one of its subclasses).
.self
Sent to a type: the type. For example, to pass the Dog type where Dog.Type is expected, you can pass Dog.self.
self
In instance code, this instance, polymorphically. In static/class code, this type, polymorphically; self.init(...) instantiates the type.
Self
In a method declaration, when specifying the return type, this class or this instance’s class, polymorphically.
http://www.apeth.com/swiftBook/ch04.html#_type_reference
swift类型操作规范的更多相关文章
- swift 类型.
swift 类型 变量声明 用let来声明常量,用var来声明变量 可以在一行中声明多个常量或者多个变量,用逗号隔开 var x = 0.0, y = 0.0, z = 0.0 类型安全 Swift ...
- Swift类型检查与转换
继承会发生在子类和父类中,如图所示,是一系列类的继承关系类图,Person是类层次结构中的根类,Student是Person的直接子类,Worker是Person的直接子类.这个继承关系类图的具体实现 ...
- Swift—类型检查与转换-备
继承会发生在子类和父类之间,是一系列类的继承关系. 例如:Person是类层次结构中的根类,Student是Person的直接子类,Worker是Person的直接子类. 这个继承关系类的具体实现代码 ...
- Swift - 类型判断is 与 类型转换as
在Swift中,通常使用is和as操作符来实现类型检查和转换.下面通过样例来演示使用方法,首先定义几个类. 1 2 3 4 5 6 7 8 9 10 11 //基类,人类 class Human{ } ...
- Swift类型推测在可选调用中的小提示
我们知道Swift中协议里也有对应于Objc中的可选方法或计算属性,当然协议必须以@objc伪指令修饰否则不可以哦. 如下示例: @objc protocol Transaction{ fun com ...
- Swift 类型桥接
前言 iOS 中的 API 基本都是在许多年前由 OC 写成的,现在通过桥接的方法在 Swift 中可以用,基本看不出区别,非常自然.但是一些特殊的类型,在两种语言进行桥接的时候需要特别注意. 1.N ...
- Swift 类型嵌套
1.类型嵌套 Swift 支持类型嵌套,把需要嵌套的类型的定义写在被嵌套的类型的 {} 中. Swift 中的枚举类型可以辅助实现特定的类或者结构体的功能. struct SchoolUniform ...
- swift类型擦除的定义-swift的类型擦除只是一个类型高低阶转换的游戏。
所谓swift的类型擦除是指: moand转换: 通过技术手段(通常是包装器),将具体类型的类型信息擦除掉了,只将类型的(某一个侧面的)抽象信息(通常指的是类型尊从的协议.接口.或基类)暴露出来. A ...
- Swift 类型检查与类型转换
前言 在 Swift 语言中一般使用 is 关键字实现类型检查,使用 as 关键字实现类型转换,除此之外还可以通过构造器和方法来实现类型转换. 1.类型检查 1.1 使用 is 检查 类型检查操作符 ...
随机推荐
- Google HTML/CSS Style Guide
转自: http://google.github.io/styleguide/htmlcssguide.xml Google HTML/CSS Style Guide Revision 2.23 Ea ...
- C#第十六节课
out using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.T ...
- Linux 系统查看命令
1. linux CPU大小cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep &quo ...
- CSS学习笔记之样式声明
目录 1.背景 2.文本 3.字体 4.列表 5.表格 6.轮廓 在这篇文章中你能看到有关于 CSS 样式设置的常用属性,文章的目录如下: 1.背景 (1)背景颜色 可以使用 background-c ...
- django数据库设置为MySQL
django默认使用sqlite,然后想使用MySQL数据库 在项目的setting文件中找到 DATABASES = { 'default': { 'ENGINE': 'django.db.back ...
- 2、Linux的关机方式
shutdown 关机指令,你可以man shutdown 来看一下帮助文档.例如你可以运行如下命令关机: shutdown –h 10 ‘This server will shutdown afte ...
- 关于 图论·并查集·HDU1232&1856
其核心是追溯其根数和链接两个数,而HDU 1856要多一步,每一个根数要标记自己和自己子数的个数,因此用结构体.注意:1856 用C写没超时,用C++写超时了╮(╯﹏╰)╭ 接下来是题目和代码: 畅通 ...
- mybatis使用-高级用法(二)
新建学生表和学生证表 --学生表 CREATE TABLE student( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'id', `nam ...
- poj 1274 基础二分最大匹配
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x3fffffff int mark[N],li ...
- 转载 - C++ bitset类使用与简介
出处:http://blog.163.com/lixiangqiu_9202/blog/static/53575037201251121331412/ C++ bitset类的使用与简介 有些程序 ...