Represents an array
Array
Represents a dictionary Dictionary <Key, Value> type
Represents a range
Range
Actually used like 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"]
//Add to the end
strings.append("yamato")
print(strings)
//["aaa", "bbb", "gagaga", "yamato"]
//Add to any position
strings.insert("mama", at: 2)
print(strings)
//["aaa", "bbb", "mama", "gagaga", "yamato"]
//There are 3 types of deletion
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]
//Change
var dictionary1 = ["key": 2]
dictionary1["key"] = 1
print(dictionary1)
//add to
var dictionary2 = ["key":3]
dictionary2["key2"] = 4
print(dictionary2)
//["key2": 4, "key": 3]
//Delete
var dictionary3 = ["key":5]
dictionary3["key"] = nil
print(dictionary3)
//[:]
chapter4.swift
//Range not including the end countableRange<Bound>Type
let range = 1..<4
for value in range {
print(value)
}
//1
//2
//3
//...Type including the end CountableClosedRange<Bound>Type
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
//Determining if the value is in the range
let range4 = 1..<10
print(range4.contains(4))
print(range4.contains(10))
//true
//false
Recommended Posts