[Swift 4.2] Array Edition
1. This how to choose data one of them, for example:
2. Sum all data in Array file :
import UIKit
class ExampleViewController: UIViewController {
let arrayInts = [ 0, 1, 3, 5, 7, 9 ]
override func viewDidLoad() {
super.viewDidLoad()
}
func sum(array:[Int]) -> Int {
return array.reduce(0, +)
}
print(sum(array: arrayInts)) // 25
}
2. Sum all data in Array file :
import UIKit
class ExampleViewController: UIViewController {
let arrayInts = [ 0, 1, 3, 5, 7, 9 ]
override func viewDidLoad() {
super.viewDidLoad()
}
func sum(array:[Int]) -> Int {
return array.reduce(0, +)
}
print(sum(array: arrayInts)) // 25
}
No comments: