Array map函数

/// Returns an array containing the results of mapping the given closure
/// over the sequence's elements.
///
/// In this example, `map` is used first to convert the names in the array
/// to lowercase strings and then to count their characters.
///
///     let cast = ["Vivien", "Marlon", "Kim", "Karl"]
///     let lowercaseNames = cast.map { $0.lowercaseString }
///     // 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"]
///     let letterCounts = cast.map { $0.characters.count }
///     // 'letterCounts' == [6, 6, 3, 4]
///
/// - Parameter transform: A mapping closure. `transform` accepts an
///   element of this sequence as its parameter and returns a transformed
///   value of the same or of a different type.
/// - Returns: An array containing the transformed elements of this
///   sequence.
public func map(_ transform: (Element) throws -> T) rethrows -> [T]
        /*
        var titles = [String]()
        for type in homeTypes {
            titles.append(type.title)
        }
        */
        
        /*
        let titles = homeTypes.map { (type : HomeType) -> String in
            return type.title
        }
        */
        let titles = homeTypes.map({ $0.title })

你可能感兴趣的:(Array map函数)