forked from jaguar07/Swift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsection-1.swift
76 lines (55 loc) · 1.51 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
71
72
73
74
75
76
// Playground - noun: a place where people can play
import UIKit
var array = ["one","two","three","four"]
for element in array {
print(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
}
print("Sum all array items: \(number)")
}
example1(array2)
func example2() -> NSMutableArray {
let 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() {
let 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)
}
//inferred types
func getClassName(obj : AnyObject) -> String {
let objectClass : AnyClass! = object_getClass(obj)
let className = objectClass.description()
return className
}
let swiftArray = [1, 2, 3]
let swiftDictionary = ["Name": "John Doe"]
let cocoaArray : NSArray = [10, 20, 30]
var mutableCocoaArray = NSMutableArray()
var 🤔 = 5
var cadena = "hola"
print(getClassName(swiftArray))
print(getClassName(swiftDictionary))
print(getClassName(cocoaArray))
print(getClassName(mutableCocoaArray))
print(getClassName(🤔))
print(getClassName(cadena))
print(🤔.description)