当前位置:网站首页>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
}
边栏推荐
猜你喜欢
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]

Fabric.js 激活输入框

Collectors. Groupingby sort

Fabric. JS gradient

centos8安裝mysql8.0.22教程

Appnuim environment configuration and basic knowledge

Black Horse Notes - - set Series Collection

Importation de studio visuel

"Original, excellent and vulgar" in operation and maintenance work

Fabric. JS iText set italics manually
随机推荐
Gee series: Unit 4 data import and export in Google Earth engine
Gee dataset: chirps pentad high resolution global grid rainfall dataset
Pyechats 1.19 generate a web version of Baidu map
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
7.TCP的十一种状态集
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
7. Eleven state sets of TCP
Applet jumps to official account
Generate QR code
Storage of data
LS1046nfs挂载文件系统
brew install * 失败,解决方法
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
摆正元素(带过渡动画)
7.1 simulation summary
Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
函数栈帧的创建和销毁
Simply encapsulate JS and apply it
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)