8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ところで Swift では Array#map が使えます

Last updated at Posted at 2014-06-14
map.rb
api_response = [
  {last_name: "Tanaka", first_name: "Taro"}, 
  {last_name: "Taguchi", first_name: "Ichiro"}, 
  {last_name: "Haraguchi", first_name: "Saburo"} 
]
full_names = api_response.map {|a| "#{a[:last_name]} #{a[:first_name]}"}

# Returns
# ["Tanaka Taro", "Taguchi Ichiro", "Haraguchi Saburo"]
map.swift
let api_response = [
  ["last_name": "Tanaka", "first_name": "Taro"],
  ["last_name": "Taguchi", "first_name": "Ichiro"],
  ["last_name": "Haraguchi", "first_name": "Saburo"]
]
let full_names = api_response.map {(a) in "\(a['last_name']) \(a['first_name'])"}

# Returns
#  ["Tanaka Taro", "Taguchi Ichiro", "Haraguchi Saburo"]

まさに神
エセC言語で痛み付けられた心が洗われますね

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?