当前位置:网站首页>I want to understand the swift code before I learn it. I understand it
I want to understand the swift code before I learn it. I understand it
2022-07-02 05:29:00 【iWillook】
/// - Note: Type Constraints in Action
func findIndex(ofString valueToFind: String, in array:
[String]) -> Int? {
for (index, value) in array.enumerated() {
if value == valueToFind {
return index
}
}
return nil
}
let anotherStrings = ["cat", "dog", "llama", "parakeet", "terrapin"]
if let foundIndex = findIndex(ofString: "llama", in: anotherStrings) {
print("The index of llama is \(foundIndex)")
}
/// - Note: Type Constraints in Action (Generic Way)
func findIndex<T: Equatable>(of valueToFind: T, in // must be Equatable
array:[T]) -> Int? {
for (index, value) in array.enumerated() {
if value == valueToFind { // not every type is equatable
return index
}
}
return nil
}
边栏推荐
- LS1046nfs挂载文件系统
- Visual Studio导入
- Generate QR code
- h5跳小程序
- Fabric.js 居中元素
- Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
- Fabric. JS iText set italics manually
- Centos8 installation mysql8.0.22 tutorial
- LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
- Record sentry's path of stepping on the pit
猜你喜欢
Visual Studio导入
Fabric.js 激活输入框
centos8安装mysql8.0.22教程
指针使用详解
Operator details
JVM class loading mechanism
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
Paddlepaddle project source code
"Original, excellent and vulgar" in operation and maintenance work
Gee series: unit 8 time series analysis in Google Earth engine [time series]
随机推荐
Software testing learning - day 4
"Original, excellent and vulgar" in operation and maintenance work
生成二维码
Fabric.js 激活输入框
Draw a wave chart_ Digital IC
Foreign trade marketing website system development function case making
Fabric. JS iText sets the color and background color of the specified text
[technical notes-08]
Fabric.js 自由绘制矩形
函数栈帧的创建和销毁
中小型项目手撸过滤器实现认证与授权
Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
Gee series: unit 8 time series analysis in Google Earth engine [time series]
Dark horse notes -- map set system
idea开发工具常用的插件合集汇总
黑马笔记---Set系列集合
Reflection of the soul of the frame (important knowledge)
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
460. LFU cache bidirectional linked list