Représente un tableau
Type de tableau
Représente un dictionnaire Type de dictionnaire <clé, valeur>
Représente une plage
Type de plage
En fait utilisé comme type Array
chapter4.swift
let a = [1,2,3]
let b = ["a","b","c"]
let array :[Int] = []
var strings = ["aaa","bbb","ccc"]
var strings1 = strings[0]
print(strings1)
//aaa
strings[2] = "gagaga"
print(strings)
["aaa", "bbb", "gagaga"]
//Ajouter à la fin
strings.append("yamato")
print(strings)
//["aaa", "bbb", "gagaga", "yamato"]
//Ajouter à n'importe quel poste
strings.insert("mama", at: 2)
print(strings)
//["aaa", "bbb", "mama", "gagaga", "yamato"]
//Il existe 3 types de suppression
var integer = [1,2,3,4,5]
integer.remove(at: 2)
integer
integer.removeLast()
integer
integer.removeAll()
integer
chapter4.swift
let dictionary = ["Key":1]
let value = dictionary["key"]
print(value)
//["key": 1]
//Changement
var dictionary1 = ["key": 2]
dictionary1["key"] = 1
print(dictionary1)
//ajouter à
var dictionary2 = ["key":3]
dictionary2["key2"] = 4
print(dictionary2)
//["key2": 4, "key": 3]
//Supprimer
var dictionary3 = ["key":5]
dictionary3["key"] = nil
print(dictionary3)
//[:]
chapter4.swift
//Gamme sans compter la fin countableRange<Bound>Moule
let range = 1..<4
for value in range {
print(value)
}
//1
//2
//3
//...Type comprenant la fin CountableClosedRange<Bound>Moule
let range2 = 1...4
for value in range2 {
print(value)
}
//1
//2
//3
//4
let range3 = 1...5
print(range3.upperBound)
print(range3.lowerBound)
//5
//1
//Déterminer si la valeur est dans la plage
let range4 = 1..<10
print(range4.contains(4))
print(range4.contains(10))
//true
//false
Recommended Posts