Given:
let numbers = [1, 2, 3, 4, 5]
Swift 3:
numbers.min() // equals 1
numbers.max() // equals 5
Swift 2:
numbers.minElement() // equals 1
numbers.maxElement() // equals 5
More Related Contents:
- How do I shuffle an array in Swift?
- Get random elements from array in Swift
- How to iterate a loop with index and element in Swift
- Why isn’t [SomeStruct] convertible to [Any]?
- How can I extend typed Arrays in Swift?
- Sort Objects in Array by date
- Sorting a Swift array by ordering from another array
- Confused about Swift Array Declarations
- Finding sum of elements in Swift array
- Swift 3.0: compiler error when calling global func min(T,T) in Array or Dictionary extension
- Swift JSONDecode decoding arrays fails if single element decoding fails
- How do I sort a swift array containing instances of NSManagedObject subclass by an attribute value (date)
- How do I make a exact duplicate copy of an array?
- Adding items to Swift array across multiple threads causing issues (because arrays aren’t thread safe) – how do I get around that?
- Count the occurences a particular integer has in an array [duplicate]
- type any? has no subscript members
- Creating an extension to filter nils from an Array in Swift
- Compare arrays in swift
- In Swift, an efficient function that separates an array into 2 arrays based on a predicate
- How do you create an immutable array in Swift?
- Is there a way to instantly generate an array filled with a range of values in Swift?
- Generic function to sort array of class or struct by properties in Swift
- Reorder array compared to another array in Swift [duplicate]
- How can I decode a JSON response with an unknown key in Swift?
- How to merge two arrays in Swift
- How to return first 5 objects of Array in Swift?
- What does $0 and $1 mean in Swift Closures?
- How to forward functions with variadic parameters?
- How can I run through three separate arrays in the same for loop?
- Swift: Binary search for standard array?