当前位置:网站首页>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
}
边栏推荐
- Briefly introduce chown command
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- Online English teaching app open source platform (customized)
- Gee: use of common mask functions in remote sensing image processing [updatemask]
- Appnuim environment configuration and basic knowledge
- 黑马笔记---Set系列集合
- Database batch insert data
- Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
- Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
- 线程池批量处理数据
猜你喜欢
随机推荐
brew install * 失败,解决方法
Two implementation methods of delay queue
JVM class loading mechanism
LS1046nfs挂载文件系统
Php/js cookie sharing across domains
Sliding window on the learning road
Small and medium-sized projects to achieve certification and authorization of hand filter
Nodejs (03) -- custom module
Draw a wave chart_ Digital IC
Online music player app
摆正元素(带过渡动画)
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
[technical notes-08]
Fabric.js IText设置指定文字的颜色和背景色
7.1模拟赛总结
Fabric.js IText 上标和下标
Pyechart1.19 national air quality exhibition
Differential identities (help find mean, variance, and other moments)
centos8安裝mysql8.0.22教程
Gee series: Unit 2 explore datasets









