-
Notifications
You must be signed in to change notification settings - Fork 23
/
Contents.swift
42 lines (33 loc) · 883 Bytes
/
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
import UIKit
// Exercise - Extensions
extension Character {
func isVowel() -> Bool {
let vowels: [Character] = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
return vowels.contains(self)
}
}
let myVowel: Character = "a"
let myConsonant: Character = "b"
print(myVowel.isVowel())
print(myConsonant.isVowel())
// -----
struct Rectangle {
var length: Double
var width: Double
}
extension Rectangle {
func half() -> Rectangle {
return Rectangle(length: length/2, width: width/2)
}
mutating func halved() {
let halvedRectangle = self.half()
self.length = halvedRectangle.length
self.width = halvedRectangle.width
}
}
var myRectangle = Rectangle(length: 10, width: 5)
print(myRectangle)
var mySmallerRectangle = myRectangle.half()
print(mySmallerRectangle)
myRectangle.halved()
print(myRectangle)