0
1

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 1 year has passed since last update.

SwiftでRangeからn回繰り返して、異なる結果のArrayを取得する

Posted at

例えば、異なるUUID10個の配列が欲しい場合

(0..<10).map { _ in UUID().uuidString }

# (10 elements) ["F4B0C448-0E10-40BF-9AAA-70FFEBB3307C", "16EC149E-7B1B-4A29-B32A-ED02B65FEC93", "398F2B91-9C9D-4526-8969-BAAD8B5A458E", "2C55C5B2-8110-410D-A8C9-34244F5BFA5B", "B0FB472D-12DB-4321-87E0-75C0E745ED39", "48A8D711-3AE8-4C76-A958-2AB02304ED63", "62B6EE3B-8EEB-47C7-A4FD-501D9CB34FE1", "71719DFB-D2D5-4005-B96E-0C8A5CDBE805", "61FB03FE-A233-4073-B72C-236D8EA5529C", "380133B2-96AB-43F6-B4D6-E6454895375C"]

ちなみに↓はすべて同じUUIDが返ってくる

Array(repeating: UUID().uuidString, count: 10)

# (10 elements) ["2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479", "2167A236-2797-487B-9B85-63FA3BFCC479"]

とりあえず思いついて動いたのでメモ。他に良い方法があれば教えてください。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?