際際滷

際際滷Share a Scribd company logo
SwiftはPythonに貌ている
2022-12-17
廉云 弯匆 @nishimotz / @24motz
Shuaruta Inc.
1
2
6/25 オ`プンセミナ`2022@レu
? Re: エンジニアのための由柴?デ`タ蛍裂秘壇
3
Swift Charts: Raise the bar
? アクセシブルなデ`タ辛晒
4
SwiftUI のために Swift を僥ぶ
5
Python の縮可を Swift に卞峅できるか
6
swift repl
7
swift package init
% mkdir hello
% cd hello
% swift package init --name hello --type executable
Creating library package: hello
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/hello/hello.swift
Creating Tests/
Creating Tests/helloTests/
Creating Tests/helloTests/helloTests.swift
8
Sources/hello/hello.swift
@main
public struct hello {
public private(set) var text = "Hello, World!"
public static func main() {
print(hello().text)
}
}
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
Swift は Python に貌ている┐海箸發△襭。
# Python
for animal in ["cat", "dog", "snake"]:
print(animal)
// Swift
for animal in ["cat", "dog", "snake"] {
print(animal)
}
Pythonに貌ている箭を冥そう
11
12
タプルの旗秘
# Python
dog, cat = ("dog", "cat")
print(dog, cat)
// Swift
var (dog, cat) = ("dog", "cat")
print(dog, cat)
13
let と var
// JavaScript の蛍護旗秘
let [dog, cat] = [^dog ̄, ^cat ̄] // 篳┘屮蹈奪スコ`プ
var [dog, cat] = [^dog ̄, ^cat ̄] // 篳┘哀踪`バル
// 協方は const
// Swift
let は協方
var は篳
14
Swiftのタプルはシ`ケンスではない
var animals = ("dog", "cat")
print(animals)
print(animals.0)
print(animals.1)
// for animal in animals {
// print(animal)
// }
// エラ`になる
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
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
17
SwiftUI で兀すとアラ`トが竃る箭
18
The craft of SwiftUI API design: Progressive disclosure
struct ContentView: View {
@State private var didSave = false
var body: some View {
Button(^Hello") {
didSave = true
}
.alert("Saved.", isPresented: $didSave) {
Button("OK") {
print("OK is pressed")
}
}
}
}
19
挑硫クロ`ジャ`
// Swift
var names = ["cat", "snake ̄, "dog"]
names.sorted { $0.count < $1.count }
# Ruby
names = ["cat", "snake ̄, "dog"]
names.sort { _1.length <=> _2.length } # since Ruby 2.7
# => ["cat", "dog", "snake"]
SwiftはRubyに貌ている
20
21
12/28 すごいレu .rb with Python

More Related Content

221217 SwiftはPythonに貌ている