namedClass:静态类型;与类型实现直接关联;可以用于初始化、类型检查等。

namedClass.self:@thick,脱敏(脱关)类型;动态类型;可以作为元类型的实例;可以作为类型参量进行传递;

可以用于继承体系;

使用脱敏类型进行初始化时,需要与具体类型进行绑定。

func  forClass() -> Swift.AnyClass?

{

let nameKey = "CFBundleName"

let appName = Bundle.main.object(forInfoDictionaryKey: nameKey) as? String   //这里也是坑,请不要翻译oc的代码,而是去NSBundle类里面看它的api

//return appName!

let className = appName! + "." + self

return NSClassFromString(className)

}

let model = vcName.forClass() as! UIViewController.Type;

namedClass.Type:元类型;用于脱敏类型声明;脱敏类型类型检查。

动态类型:编译时不确定类型指定。

Self:动态时的具体类型。

Self:In that context, Self refers to the eventual type that conforms to the protocol.

代表具体的实际类型;动态类型。

https://docs.swift.org/swift-book/ReferenceManual/Declarations.html

"Self" is a placeholder used in two different cases:

1. In a protocol, it refers to the type that conforms to the protocol in any particular use. In Equatable, for example, it's used to require that the two values being compared are of the same type. It's something like a generic type parameter that you don't have to put between the <…> because it's deduced from the context of its use.

2. In a class/static method, it can be used as the return type, to indicate that the return type is the type of the class to which the method was sent, rather than the class in which the method is declared. It's similar to 'instancetype' in Obj-C.

AnyObject:

an untyped object

/// The flexible behavior of the `AnyObject` protocol is similar to

/// Objective-C's `id` type. For this reason, imported Objective-C types

/// frequently use `AnyObject` as the type for properties, method parameters,

/// and return values.

///

/// Casting AnyObject Instances to a Known Type

/// ===========================================

///

/// Objects with a concrete type of `AnyObject` maintain a specific dynamic

/// type and can be cast to that type using one of the type-cast operators

/// (`as`, `as?`, or `as!`).

Swift provides two special types for working with nonspecific types:

  • Any can represent an instance of any type at all, including function types.
  • AnyObject can represent an instance of any class type.

Whether you use Any or AnyObject depends on your intended use:

If your dictionary will be used only within Swift code, then you should use Any because your types (IntDoubleFloatStringArray, and Dictionary) are not objects.

If you will be passing your dictionary to Objective-C routines that expect an NSDictionary, then you should use AnyObject.

When you import Foundation or import UIKit or import Cocoa, it is possible to declare your array as [String: AnyObject], but in this case Swift is treating your IntDoubleFloatliterals as NSNumber, your Strings as NSString, your Arrays as NSArray, and your dictionaries as NSDictionary, all of which are objects. A dictionary using AnyObject as the value type is convertible to NSDictionary, but one using Any is not.

https://stackoverflow.com/questions/25809168/anyobject-and-any-in-swift

swift 类型系统 Self self Type的更多相关文章

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

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

  2. 寒哥带你深入了解下Swift中的Value Type

    http://www.cocoachina.com/swift/20150923/13539.html 关于开发到底使用ValueType 值类型还是Reference Type 引用类型,关于这个, ...

  3. swift 定义类方法(type methed)

    swift   中声明结构体或者枚举的类型方法,需要在func前加上关键字 ststic  ,但是如果要定义一个类的类方法时,需要用关键字 class class SomeClass { class ...

  4. Swift:Minimizing Annotation with Type Inference

    许多程序猿更喜欢比如Python和Javascript这样的动态语言,因为这些语言并不要求程序猿为每个变量声明和管理它们的类型. 在大多数动态类型的语言里,变量可以是任何类型,而类型声明是可选的或者根 ...

  5. swift:Optional Type 、Swift和Objective-C混编的讲解

    ❤️❤️❤️swift中的Optional Type的?和!含义:其实就是一个装包和拆包的过程 optional的含义: Optional事实上是一个枚举类型,Optional包含None和Some两 ...

  6. iOS开发系列--Swift进阶

    概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...

  7. iOS8.3发布了Swift 1.2带来哪些新变化

    苹果前几日在面向开发者推送iOS 8.3 Beta的同时,还发布了版本号为6D520o的Xcode 6.3 Beta,其中便包含了iOS 8.3 Beta和OS X v10.10 SDK,并进一步提升 ...

  8. Swift数据类型简介(二)

    整数 整数就是没有小数部分的数字,比如42和-23.整数可以是有符号(正.负.零)或者无符号(正.零). Swift 提供了8,16,32和64位的有符号和无符号整数类型.这些整数类型和 C 语言的命 ...

  9. swift中文文档- 类型转换

    未翻译完 待续(英语烂,求斧正) Type Casting 类型转换 Type casting is a way to check the type of an instance, and/or to ...

随机推荐

  1. 动态加入的HTML的自己主动渲染

    这两天在写一个用EasyUI的前台,遇到动态向Layout加入HTML内容时没有自己主动渲染的问题.查了一下网上的资料后得以解决.详细例如以下: $("#content").htm ...

  2. Java对二叉搜索树进行插入、查找、遍历、最大值和最小值的操作

    1.首先,须要一个节点对象的类.这些对象包括数据.数据代表存储的内容,并且还有指向节点的两个子节点的引用 class Node { public int iData; public double dD ...

  3. volley基本使用方法

    用volley訪问server数据,不用自己额外开线程.以下样例为訪问JSONObject类型的数据,详细使用方法看代码: 首先得有volley的jar包,假设自己没有.去github上下载,然后自己 ...

  4. LA 4329(树状数组)

    算法竞赛入门经典 p197 题目大意: 一条大街上住着n个乒乓球爱好者.常常比赛切磋技术.每一个人都有一个不同的技能值a[i].每场比赛须要3个人:两名选手,一名裁判.他们有个奇怪的约定,裁判必须住在 ...

  5. oop_day02_类、重载_20150810

    oop_day02_类.重载_20150810 1.怎样创建类?怎样创建对象? 2.引用类型之间画等号: 家门钥匙 1)指向同一个对象(数据有一份) 2)对当中一个引用的改动.会影响另外一个引用 基本 ...

  6. ConcurrentDictionary中的 TryRemove

    class A { internal int value; } ConcurrentDictionary<int, A> dic = new ConcurrentDictionary< ...

  7. [POJ 2536] Gopher ||

    [题目链接] http://poj.org/problem?id=2536 [算法] 匈牙利算法解二分图最大匹配 [代码] #include <algorithm> #include &l ...

  8. B1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 数学

    今天净做水题了,这个题还不到十五分钟就搞定了,思路特别简单,就是直接按照线性求因子个数的思路就行了. 题干: Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜 ...

  9. 欧拉函数&&欧拉定理

    定义和简单性质 欧拉函数在OI中是个非常重要的东西,不知道的话会吃大亏的. 欧拉函数用希腊字母φ表示,φ(N)表示N的欧拉函数. 对φ(N)的值,我们可以通俗地理解为小于N且与N互质的数的个数(包含1 ...

  10. 完美解决 linux sublime 中文无法输入

    感谢oschina 中几位前辈的分享 下面是我结合自己的情况所配置的具体步骤: 系统环境: ubuntu 12.10 输入法:fcitx fcitx 安装 apt-get install fcitx ...