当前位置:网站首页>Do you feel like you've learned something and forgotten it?
Do you feel like you've learned something and forgotten it?
2022-07-03 12:34:00 【iWillook】
extension Int {
func repetitions(task: () -> Void) {
for _ in 0..<self {
task()
}
}
mutating func square() {
self = self * self
}
subscript(digitIndex: Int) -> Int {
var decimalBase = 1
for _ in 0..<digitIndex {
decimalBase *= 10
}
return (self / decimalBase) % 10
}
enum Kind {
case negative, positive, zero
}
var kind: Kind {
switch self {
case 0:
return .zero
case let x where x > 0:
return .positive
default:
return .negative
}
}
}
var i = 0
9.repetitions {
print(987239847[i])
i += 1
}
var someInt = 3
someInt.square()
func printIntegerKinds(_ numbers: [Int]) {
for number in numbers {
switch number.kind {
case .negative:
print("- ", terminator: "")
case .zero:
print("0 ", terminator: "")
case .positive:
print("+ ", terminator: "")
}
}
print("")
}
printIntegerKinds([3, 19, -27, 0, -6, 0, 7])
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 5.3).” Apple Books. https://books.apple.com/us/book/the-swift-programming-language-swift-5-3/id881256329
边栏推荐
- 2021 autumn Information Security Experiment 1 (password and hiding technology)
- Sqoop1.4.4原生增量导入特性探秘
- 手机号码变成空号导致亚马逊账号登陆两步验证失败的恢复网址及方法
- Oh my Zsh + TMUX installation
- Swagger
- 2.8 overview of ViewModel knowledge
- node的ORM使用-Sequelize
- (construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
- repo Manifest Format
- Nodejs+Express+MySQL实现登陆功能(含验证码)
猜你喜欢
剑指Offer04. 二维数组中的查找【中等】
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
剑指Offer07. 重建二叉树
(construction notes) ADT and OOP
Wechat applet pages always report errors when sending values to the background. It turned out to be this pit!
Swagger
Eureka self protection
Shutter: overview of shutter architecture (excerpt)
If you can't learn, you have to learn. Jetpack compose writes an im app (I)
[ManageEngine] the role of IP address scanning
随机推荐
Airflow installation jump pit
Sword finger offer09 Implementing queues with two stacks
111. Minimum depth of binary tree
(構造筆記)從類、API、框架三個層面學習如何設計可複用軟件實體的具體技術
Dart: self study system
Sword finger offer05 Replace spaces
实现验证码验证
[ManageEngine] the role of IP address scanning
elastic_ L02_ install
Sword finger offer04 Search in two-dimensional array [medium]
Oh my Zsh + TMUX installation
Redis
Apprendre à concevoir des entités logicielles réutilisables à partir de la classe, de l'API et du cadre
(construction notes) learning experience of MIT reading
2021 autumn Information Security Experiment 1 (password and hiding technology)
Lambda表达式
剑指Offer04. 二维数组中的查找【中等】
RedHat5 安装Socket5代理服务器
Applet wxss introduction
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.