9. 9
swift run
% swift run
Building for debugging...
[3/3] Linking hello
Build complete! (0.96s)
Hello, World!
% file ./.build/x86_64-apple-macosx/debug/hello
./.build/x86_64-apple-macosx/debug/hello: Mach-O 64-bit executable x86_64
10. 10
Swift は Python に貌ている┐海箸發△襭。
# Python
for animal in ["cat", "dog", "snake"]:
print(animal)
// Swift
for animal in ["cat", "dog", "snake"] {
print(animal)
}
13. 13
let と var
// JavaScript の蛍護旗秘
let [dog, cat] = [^dog ̄, ^cat ̄] // 篳┘屮蹈奪スコ`プ
var [dog, cat] = [^dog ̄, ^cat ̄] // 篳┘哀踪`バル
// 協方は const
// Swift
let は協方
var は篳
14. 14
Swiftのタプルはシ`ケンスではない
var animals = ("dog", "cat")
print(animals)
print(animals.0)
print(animals.1)
// for animal in animals {
// print(animal)
// }
// エラ`になる
15. 15
Pythonの屎ア蹶F
import re
s = "My name is Taylor and I'm 26 years old."
m = re.search("My name is (.+?) and I'm (d+) years old.", s)
if m:
print(f"Name:{m.group(1)}")
print(f"Age:{m.group(2)}")
16. 16
Swiftの屎ア蹶F
let s = "My name is Taylor and I'm 26 years old."
let m = /My name is (.+?) and I'm (d+) years old./
if let g = try? m.wholeMatch(in: s) {
print("Name: (g.1)")
print("Age: (g.2)")
}
// since Swift 5.7