Avatar
(edited)
Author icon
t.ae
let rows: [(id: Int, name1: String, name2: String)] = [ (0, "x", "y"), (1, "z", "w") ] let results1 = rows.flatMap { row in var entries = [(Int, String)]() entries.append((row.id, row.name1)) entries.append((row.id, row.name2)) return entries }
Version:
swift-4.2.1-RELEASE
Output:
Error:
/usercode/main.swift:10:12: error: cannot convert return expression of type '[(Int, String)]' to return type 'String?' return entries ^~~~~~~ /usercode/main.swift:6:21: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value let results1 = rows.flatMap { row in ^ /usercode/main.swift:6:21: note: use 'compactMap(_:)' instead let results1 = rows.flatMap { row in ^~~~~~~ compactMap
5:04 AM