Swift: Getting the average

This entry is part 39 of 41 in the series Swift

Another method to get the average.

import UIKit

func calculateAverage(total: Int, countOfNumbers: Int) -> Int {
    return total / countOfNumbers
}

func average(algorithm: (Int, Int) -> Int, numbers: Int...) -> Int {
    var countOfNumbers = 0
    var total = 0
    
    for number in numbers {
        total += number
        countOfNumbers++
    }
    
    return algorithm(total, countOfNumbers)
}

let avg = average(calculateAverage, numbers: 3, 9, 6)

print(avg)

average

Hello World IOS App Part 2 AutoLayout: IOS Swift Tutorial

This entry is part 6 of 32 in the series iOS Apps

This IOS tutorial shows how to build first ios app hello world in swift and add autolayout constraints to arrange the uilabel centered horizontally and vertically with respect to parent view with the align center x to superview and align center y to superview constraints. It also shows how to change text color of UILabel and background color of UIView