forked from sbarex/SourceCodeSyntaxHighlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.swift
More file actions
35 lines (26 loc) · 678 Bytes
/
Copy pathexample.swift
File metadata and controls
35 lines (26 loc) · 678 Bytes
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
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Declare String value
let firstName:String = "Sergey"
// Declare Int value
let intNumber:Int=5
// Call the "takeAway()" function we have extended the Int class with:
print("5 take away 4 equals \(intNumber.takeAway(4))")
// Call the greatTheWorld() function we have extended the String class with
firstName.greatTheWorld()
}
}
// Extend the String class in Swift
extension String {
func greatTheWorld() {
print("Hello world")
}
}
// Extend the Int class in Swift
extension Int {
func takeAway(a:Int)->Int {
return self-a;
}
}