-
Notifications
You must be signed in to change notification settings - Fork 1
/
Contents.swift
46 lines (37 loc) · 1.02 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import UIKit
// Challenge step 1
extension UIView {
func bounceOut(duration: TimeInterval) {
UIView.animate(withDuration: duration) { [unowned self] in
self.transform = CGAffineTransform(scaleX: 0.0001, y: 0.0001)
}
}
}
let testView = UIView()
testView.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
print("size width=\(testView.frame.width)")
testView.bounceOut(duration: 10)
print("size width=\(testView.frame.width)")
// Challenge step 2
extension Int {
func times(_ closure: () -> Void) {
guard self > 0 else { return }
for _ in 0 ..< self {
closure()
}
}
}
5.times { print("Hello!") }
0.times { print("Hello!") }
10.times { print("Hello!") }
// Challenge step 3
extension Array where Element: Comparable {
mutating func remove(item: Element) {
if let index = self.firstIndex(of: item) {
self.remove(at: index)
}
}
}
var arr = ["red", "green", "blue"]
arr.remove(item: "green")
arr.remove(item: "fred")