[swift] A Swift Tour -Simple Values
📌 Appleの公式文書「SWIFTプログラミング言語」(SWIFT 5.5)のA SWIFT Toorは、その名の通り、「クイックブラウズ」で整理された文章です.
📙Simple Values
タイプX→コンパイラ推定 タイプを常に明確に記入する必要がありますファジイまたは初期値がない場合、明示的な表示タイプ
値は暗黙的に他のタイプに変換する、X→明示的に に変換する.文字列に他のタイプをより簡単に含めるには、次の手順に従います.
使用→(values)
インデックスまたはキー値によって要素 にアクセスする.最後の要素の後ろのカンマ であることができる.
📙Simple Values
📎let and var
var myVariable = 42
myVariable = 50
let myConstant = 42
myConstant = 50 🚫 상수 값 변경 불가능
var myVariable = 42
myVariable = 50
let myConstant = 42
myConstant = 50 🚫 상수 값 변경 불가능
let implicitDouble = 70.0 // explicit
let explictDouble: Double = 50 // implicit
📎Convert to another type
let label = "The width is "
let width = 94
let widthLabel = label + String(width)
//let widthLabel = label + width 🚫
let apples = 3
let oranges = 5
let appleSummary = "I have \(apples) apples." // I have 3 apples.
let fruitSummary = "I have \(apples + oranges) pieces of fruit." // I have 8 pieces of fruit.
使用→(values)
📎Multiple lines of string: use """
let quotation = """
I said "I have \(apples) apples."
And then I said "I have \(apples + oranges) pieces of fruit."
"""
📎Arrays and Dictionaries
,
は- Array
let emptyArray: [String] = [] // empty array 선언
var shoppingList = ["catfish", " water", "tulips"] // array 선언
shoppingList.append("blue paint") //element 추가
- Dictionary
let emptyDictionary: [String:Float]=[:] // empty dictionary 선언
var occupations = ["Malcolm": "Captain", "Kaylee": "Mechanic"] // dictionary 선언
occupations["Jayne"] = "Public Relations" // element 추가
Reference
この問題について([swift] A Swift Tour -Simple Values), 我々は、より多くの情報をここで見つけました https://velog.io/@imeyh/swift-Swift-Tour-Simple-Valuesテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol