当前位置: 首页 > wzjs >正文

哪里有做效果图的网站邢台人才网官网首页

哪里有做效果图的网站,邢台人才网官网首页,来年做那些网站能致富,wordpress分享到+滑动一个朴实无华的目录 今日学习内容:1.Swift 泛型1.1泛型类型1.2扩展泛型类型1.3类型约束1.4关联类1.5Where 语句 2.Swift 访问控制2.1语句函数类型访问权限:元组的访问级别与元组中访问级别最低的类型一致子类的2.2访问级别不得高于父类的访问级别2.3常量…

一个朴实无华的目录

  • 今日学习内容:
    • 1.Swift 泛型
      • 1.1泛型类型
      • 1.2扩展泛型类型
      • 1.3类型约束
      • 1.4关联类
      • 1.5Where 语句
    • 2.Swift 访问控制
      • 2.1语句函数类型访问权限:元组的访问级别与元组中访问级别最低的类型一致子类的
      • 2.2访问级别不得高于父类的访问级别
      • 2.3常量、变量、属性、下标访问权限:不能拥有比它们的类型更高的访问级别。
      • 2.4Setter的访问级别可以低于对应的Getter的访问级别
      • 2.5构造器和默认构造器访问权限:在每个子类的 init() 方法前使用 required 关键字声明访问权限。
      • 2.6类型别名:任何你定义的类型别名都会被当作不同的类型,以便于进行访问控制。一个类型别名的访问级别不可高于原类型的访问级别。

今日学习内容:

1.Swift 泛型

1.1泛型类型

// 定义一个交换两个变量的函数
func swapTwoValues<T>(_ a: inout T, _ b: inout T) {let temporaryA = aa = bb = temporaryA
}var numb1 = 100
var numb2 = 200print("交换前数据:  \(numb1)\(numb2)")
swapTwoValues(&numb1, &numb2)
print("交换后数据: \(numb1)\(numb2)")var str1 = "A"
var str2 = "B"print("交换前数据:  \(str1)\(str2)")
swapTwoValues(&str1, &str2)
print("交换后数据: \(str1)\(str2)")

Stack 基本上和 IntStack 相同,占位类型参数 Element 代替了实际的 Int 类型。

以上实例中 Element 在如下三个地方被用作占位符:

创建 items 属性,使用 Element 类型的空数组对其进行初始化。
指定 push(_😃 方法的唯一参数 item 的类型必须是 Element 类型。
指定 pop() 方法的返回值类型必须是 Element 类型。

struct Stack<Element> {var items = [Element]()mutating func push(_ item: Element) {items.append(item)}mutating func pop() -> Element {return items.removeLast()}
}var stackOfStrings = Stack<String>()
print("字符串元素入栈: ")
stackOfStrings.push("google")
stackOfStrings.push("runoob")
print(stackOfStrings.items);let deletetos = stackOfStrings.pop()
print("出栈元素: " + deletetos)var stackOfInts = Stack<Int>()
print("整数元素入栈: ")
stackOfInts.push(1)
stackOfInts.push(2)
print(stackOfInts.items);

1.2扩展泛型类型

为其添加了一个名为 topItem 的只读计算型属性,它将会返回当前栈顶端的元素而不会将其从栈中移除:

struct Stack<Element> {var items = [Element]()mutating func push(_ item: Element) {items.append(item)}mutating func pop() -> Element {return items.removeLast()}
}extension Stack {var topItem: Element? {return items.isEmpty ? nil : items[items.count - 1]}
}var stackOfStrings = Stack<String>()
print("字符串元素入栈: ")
stackOfStrings.push("google")
stackOfStrings.push("runoob")if let topItem = stackOfStrings.topItem {print("栈中的顶部元素是:\(topItem).")
}print(stackOfStrings.items)
实例中 topItem 属性会返回一个 Element 类型的可选值。当栈为空的时候,topItem 会返回 nil;当栈不为空的时候,topItem 会返回 items 数组中的最后一个元素。以上程序执行输出结果为:字符串元素入栈: 
栈中的顶部元素是:runoob.
["google", "runoob"]

1.3类型约束

// 非泛型函数,查找指定字符串在数组中的索引
func findIndex(ofString valueToFind: String, in array: [String]) -> Int? {for (index, value) in array.enumerated() {if value == valueToFind {// 找到返回索引值return index}}return nil
}let strings = ["google", "weibo", "taobao", "runoob", "facebook"]
if let foundIndex = findIndex(ofString: "runoob", in: strings) {print("runoob 的索引为 \(foundIndex)")
}

1.4关联类

// Container 协议
protocol Container {associatedtype ItemType// 添加一个新元素到容器里mutating func append(_ item: ItemType)// 获取容器中元素的数var count: Int { get }// 通过索引值类型为 Int 的下标检索到容器中的每一个元素subscript(i: Int) -> ItemType { get }
}// Stack 结构体遵从 Container 协议
struct Stack<Element>: Container {// Stack<Element> 的原始实现部分var items = [Element]()mutating func push(_ item: Element) {items.append(item)}mutating func pop() -> Element {return items.removeLast()}// Container 协议的实现部分mutating func append(_ item: Element) {self.push(item)}var count: Int {return items.count}subscript(i: Int) -> Element {return items[i]}
}var tos = Stack<String>()
tos.push("google")
tos.push("runoob")
tos.push("taobao")
// 元素列表
print(tos.items)
// 元素个数
print( tos.count)
以上程序执行输出结果为:["google", "runoob", "taobao"]
3

1.5Where 语句

// 扩展,将 Array 当作 Container 来使用
extension Array: Container {}func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) -> Boolwhere C1.ItemType == C2.ItemType, C1.ItemType: Equatable {// 检查两个容器含有相同数量的元素if someContainer.count != anotherContainer.count {return false}// 检查每一对元素是否相等for i in 0..<someContainer.count {if someContainer[i] != anotherContainer[i] {return false}}// 所有元素都匹配,返回 truereturn true
}
var tos = Stack<String>()
tos.push("google")
tos.push("runoob")
tos.push("taobao")var aos = ["google", "runoob", "taobao"]if allItemsMatch(tos, aos) {print("匹配所有元素")
} else {print("元素不匹配")
}
以上程序执行输出结果为:匹配所有元素

2.Swift 访问控制

除非有特殊的说明,否则实体都使用默认的访问级别 internal。
请添加图片描述

2.1语句函数类型访问权限:元组的访问级别与元组中访问级别最低的类型一致子类的

2.2访问级别不得高于父类的访问级别

2.3常量、变量、属性、下标访问权限:不能拥有比它们的类型更高的访问级别。

2.4Setter的访问级别可以低于对应的Getter的访问级别

class Samplepgm {fileprivate var counter: Int = 0{willSet(newTotal){print("计数器: \(newTotal)")}didSet{if counter > oldValue {print("新增加数量 \(counter - oldValue)")}}}
}let NewCounter = Samplepgm()
NewCounter.counter = 100
NewCounter.counter = 800
counter 的访问级别为 fileprivate,在文件内可以访问。以上程序执行输出结果为:计数器: 100
新增加数量 100
计数器: 800
新增加数量 700

2.5构造器和默认构造器访问权限:在每个子类的 init() 方法前使用 required 关键字声明访问权限。

2.6类型别名:任何你定义的类型别名都会被当作不同的类型,以便于进行访问控制。一个类型别名的访问级别不可高于原类型的访问级别。

public protocol Container {typealias ItemTypemutating func append(item: ItemType)var count: Int { get }subscript(i: Int) -> ItemType { get }
}struct Stack<T>: Container {// original Stack<T> implementationvar items = [T]()mutating func push(item: T) {items.append(item)}mutating func pop() -> T {return items.removeLast()}// conformance to the Container protocolmutating func append(item: T) {self.push(item)}var count: Int {return items.count}subscript(i: Int) -> T {return items[i]}
}func allItemsMatch<C1: Container, C2: Containerwhere C1.ItemType == C2.ItemType, C1.ItemType: Equatable>(someContainer: C1, anotherContainer: C2) -> Bool {// check that both containers contain the same number of itemsif someContainer.count != anotherContainer.count {return false}// check each pair of items to see if they are equivalentfor i in 0..<someContainer.count {if someContainer[i] != anotherContainer[i] {return false}}// all items match, so return truereturn true
}var tos = Stack<String>()
tos.push("Swift")
print(tos.items)tos.push("泛型")
print(tos.items)tos.push("Where 语句")
print(tos.items)var eos = ["Swift", "泛型", "Where 语句"]
print(eos)
以上程序执行输出结果为:["Swift"]
["Swift", "泛型"]
["Swift", "泛型", "Where 语句"]
["Swift", "泛型", "Where 语句"]

文章转载自:

http://oFwbQxvU.dnbhd.cn
http://5KQ5nUby.dnbhd.cn
http://JlAwRvHq.dnbhd.cn
http://Zbai5OMU.dnbhd.cn
http://f0XnegzK.dnbhd.cn
http://DwiOyr15.dnbhd.cn
http://6zIrUGR3.dnbhd.cn
http://qxacPZ0y.dnbhd.cn
http://IrE9pjm6.dnbhd.cn
http://MRoLN9dh.dnbhd.cn
http://FFNGGeMG.dnbhd.cn
http://VBlH09LI.dnbhd.cn
http://KgdGSAGr.dnbhd.cn
http://rOg02WPF.dnbhd.cn
http://Y6ZQyfLV.dnbhd.cn
http://xSnnNOIx.dnbhd.cn
http://SjWFdd2M.dnbhd.cn
http://7gwMOlNJ.dnbhd.cn
http://qzBZFB1T.dnbhd.cn
http://RuQluB9q.dnbhd.cn
http://8gTe4rX6.dnbhd.cn
http://HoJirlnp.dnbhd.cn
http://hfDxz8aj.dnbhd.cn
http://XltzSUYW.dnbhd.cn
http://nzQeHB0I.dnbhd.cn
http://o0eHQApM.dnbhd.cn
http://GTpZ5LEW.dnbhd.cn
http://NC4yAFXm.dnbhd.cn
http://pTRUpArd.dnbhd.cn
http://8W8Q7F1B.dnbhd.cn
http://www.dtcms.com/wzjs/624221.html

相关文章:

  • 自己做网站排名好吗网站的主题
  • 做网站接广告怎么用壳域名做网站
  • 个人视频网站注册平台4G访问wordpress
  • 什么类型客户做网站网站怎么百度收录
  • 建设银行招聘网站天津住房与城乡建设厅网站
  • 广州互联网网站建设php网站开发实例教程作业
  • 好创意的设计网站租用服务器做视频网站
  • 北戴河网站建设建设网站那些公司好
  • 莱阳网站定制做欧洲电商看哪个网站吗
  • 广告公司网站设计策划网站建设创业项目简介
  • sem分析是什么意思windows优化大师要会员
  • 网站验收流程计算机专业学什么好
  • 国外好的室内设计网站做网站送的小程序有什么用
  • nas做网站需要备案吗二级网站建设与管理会议
  • 网站信息发布和内容建设自查报告设计公司logo图片
  • 河北省建设招标网站wordpress高级培训
  • 哪个做砍价活动的网站好wordpress全端美化
  • 扬州市广陵区建设局网站插件 wordpress开发教程
  • 简洁的企业网站源码仿克米设计网站
  • 小公司网站如何做wordpress怎么变成pdf
  • 初中信息技术 网站制作帮公司制作一个网站是如何收费
  • 找网站建设wordpress实现分享
  • 域名解析查询站长工具银川网站建设报价
  • 婚庆网站源码扬州恒通建设网站
  • 河南省招生网站服务平台免费网站的代码
  • 嵊州哪里可以做网站创意网页设计模板
  • 网站建设合同 费用网站维护多少钱一个月
  • python做网站用什么惠山网站建设
  • dede程序网站如何查看百度蜘蛛分析网页设计
  • 怎样分析网站做seo网络工具