forked from jaguar07/Swift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsection-1.swift
91 lines (36 loc) · 1 KB
/
section-1.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Playground - noun: a place where people can play
import UIKit
var array = ["one","two","three","four"]for element in array { println(element)
}
var array2 = [1,2,3,4,5,6,7,8,9,10];
func example1(integers: NSArray) {
var number:NSInteger = 0
for element in integers{
number += (element as! NSNumber).integerValue
}
println("Sum all array items: \(number)")
}
example1(array2)
func example2() -> NSMutableArray {
var array = NSMutableArray()
for var i = 11; i<=20; i++ {
array.addObject(i)
}
return array
}
var array3 = example2()
//show nsmutable array value sum
example1(array3)
//delete pair items from array
func example3() {
var array = example2()
for var i = 0; i<array.count; i++ {
if ((array.objectAtIndex(i) as! Int % 2) == 0){
array.removeObjectAtIndex(i)
}
}
//print pair items from array
example1(array)
}