Created
February 25, 2017 13:16
-
-
Save stulevine/67c9063db95573a857bd8d3cac6ecc0c to your computer and use it in GitHub Desktop.
Example of how to use .reduce in Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
struct ChartItem { | |
var label: String = "" | |
var value: CGFloat = 0.0 | |
} | |
let data = [ChartItem(label: "one", value: 350.0), | |
ChartItem(label: "two", value: 1310.0), | |
ChartItem(label: "two", value: 750.0), | |
ChartItem(label: "three", value: 890.0), | |
ChartItem(label: "two", value: 230.0)] | |
let maxBaseHeight = data.reduce(0.0, { (total, item) -> CGFloat in | |
max(total, item.value) | |
}) | |
print("maxBaseHeight: \(maxBaseHeight)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment