Slide 1

Slide 1 text

try! Swift Tokyo 2024 After Talk Presented by: Kenta Enomoto, STORES, Inc. Date: March 27, 2024 Introducing Pkl

Slide 2

Slide 2 text

About Me 2 Kenta Enomoto STORES, Inc. Branded App Team iOS Engineer twitter.com/enomotok_ github.com/enomoto

Slide 3

Slide 3 text

About Pkl 3 ● An open-source language developed by Apple ● Configuration that is programmable, scalable, and safe ● Generates output for JSON, YAML, Property Lists, XML, and more ● /ˈpɪk.əl/ https://pixabay.com/photos/pickles-blanks-cucumbers-1799731/

Slide 4

Slide 4 text

Basic Syntax 4 name = "Swallow" job { title = "Sr. Nest Maker" company = "Nests R Us" yearsOfExperience = 2 } sample.pkl

Slide 5

Slide 5 text

Basic Syntax (with Class) 5 amends "../Environment.pkl" appmakerClientId = "a1b2c3d4e5g6h7i8j9k0A1" appmakerTemplateId = "4649" isDarkContentBarStyle = true itemsPerPage = 20 appearance { colorAccent = "#333333FF" colorAccentLight = "#D3D3D3FF" colorPrimary = "#FFFFFFFF" } myEnvironment.pkl import "Appearance.pkl" appmakerClientId: String appmakerTemplateId: String isDarkContentBarStyle: Boolean itemsPerPage: Int appearance: Appearance Environment.pkl

Slide 6

Slide 6 text

Validation 6 import "Appearance.pkl" appmakerClientId: String appmakerTemplateId: String(this.length == 4) itemsPerPage: Int(this > 0 && this < 50) isDarkContentBarStyle: Boolean appearance: Appearance Environment.pkl colorAccent: String(this.startsWith("#") && (this.length == 7 || this.length == 9)) colorAccentLight: String(this.matches(Regex("^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$"))) // You can even use regex colorPrimary: String Appearance.pkl

Slide 7

Slide 7 text

Code Generation with Pkl 7 amends "../Environment.pkl" appmakerClientId = "a1b2c3d4e5g6h7i8j9k0A1" appmakerTemplateId = "4649" isDarkContentBarStyle = true itemsPerPage = 20 appearance { colorAccent = "#333333FF" colorAccentLight = "#D3D3D3FF" colorPrimary = "#FFFFFFFF" } myEnvironment.pkl { "appmakerClientId": "a1b2c3d4e5g6h7i8j9k0A1", "appmakerTemplateId": "4649", "isDarkContentBarStyle": true, "itemsPerPage": 20, "appearance": { "colorAccent": "#333333FF", "colorAccentLight": "#D3D3D3FF", "colorPrimary": "#FFFFFFFF" } } my_environment.json $ pkl eval -f json myEnvironment.pkl -o my_environment.json

Slide 8

Slide 8 text

Use Cases 8 ● Originally developed as a server technology ● Generate Kubernetes manifest files

Slide 9

Slide 9 text

Use Cases for iOS Apps 9 ● Automatically generate multiple apps from the same codebase by injecting configuration items. ● For managing the configuration of large applications with YAML or JSON, you can generate configuration files with type safety (Hello XcodeGen.) ● Let me know your ideas.

Slide 10

Slide 10 text

Integration with iOS Apps 10 ● PklSwift ○ Swift Code generation from Pkl ○ fully type-safe ○ Interface with Swift Concurrency ○ https://github.com/apple/pkl-swift ● PklSwift does not work for iOS (yet.)

Slide 11

Slide 11 text

Integration with iOS Apps 11 Generate property lists and JSON files using the pkl eval command.

Slide 12

Slide 12 text

References 12 https://pkl-lang.org/ https://github.com/apple/pkl https://github.com/apple/pkl-swift https://news.ycombinator.com/item?id=39232976

Slide 13

Slide 13 text

Thank you 13 Enjoy your daily configuration :D