0
2

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 配列のメモ

Last updated at Posted at 2019-06-06

##宣言の書き方

let emojis = ["🍽","🍎","🍧","🍻","🏋️‍♀️","👔","💇🏻‍♂️","🧻","🏝","🏡","🌟","🚰","🚌","🚗","📱","📚","🏥","🏪"]
var days:[String] = []
var moneys:[Int16:String] = [:]
var arrayFloats: Array<Float> = Array()

指定要素分を固定値で初期化
Array(repeating: 初期値, count: 要素数)

var myArray = Array(repeating: 0, count: 3)

結果:
[0,0,0]
##配列要素の追加

        emojis.append("m")
        emojis += ["m"]

##配列を結合する

let s: String = emojis.joined()
let s: String = emojis.joined(separator: "-")

##Sort

let s = emojis.sorted()
emojis.sort()
//複雑な配列の場合
struct Person {
    var name: String
    var sex:Bool
}

var users = [...]

users.sort {$0.name < $1.name}
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?