Open16

iOS アプリ開発のチュートリアルをやってみるスクラップ

てべすてんてべすてん

まずはこれ軽く読んだ方がいいらしい
Swift の基礎文法まとめ的なやつ

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/

てべすてんてべすてん

kotlin と違う

定数は let キーワードで、変数は var キーワードで宣言

let が定数なのねぇ、TS だと変数だからちょっと変な感じ

てべすてんてべすてん

kotlinと違う
複数行コメント /* */ をネストできる....! イイネ

/* This is the start of the first multiline comment.
    /* This is the second, nested multiline comment. */
This is the end of the first multiline comment. */
てべすてんてべすてん

kotlin と違う

ほとんどの場合、コード内で使用する整数の特定のサイズを選択する必要はありません。Swift はInt、現在のプラットフォームのネイティブ ワード サイズと同じサイズを持つ追加の整数型 を提供します。

32 ビット プラットフォームでは、Intは と同じサイズですInt32。

64 ビット プラットフォームでは、Intは と同じサイズですInt64。

サイズが色々ある。が、 一旦 Int を使っとくのが安牌とのこと

てべすてんてべすてん
let some10進数 = 17
let some2進数 = 0b10001       // 17 in binary notation
let some8進数 = 0o21           // 17 in octal notation
let some16進数 = 0x11     // 17 in hexadecimal notation
てべすてんてべすてん

kotlinと違う
Byte とか Short とかがごちゃごちゃしてる kotlin/java より swift の方が整数データ型の命名が Int8, Int32, Int64 と単純でわかりやすいわね イイネェ

てべすてんてべすてん

kotlinと違う

タプル使い勝手良さそうで良き

let (x, _, z) = (1,2,3)
let point = (4, 5)
point.0 // 4
point.1 // 5

let point = (x: 10, y: 20)