Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Pkl

Introducing Pkl

This presentation was delivered at the try! Swift Tokyo 2024 After Talk, a gathering of Swift programming enthusiasts and professionals. For more details about the event, visit https://hey.connpass.com/event/312785/

Kenta Enomoto

March 27, 2024
Tweet

More Decks by Kenta Enomoto

Other Decks in Technology

Transcript

  1. try! Swift Tokyo 2024 After Talk Presented by: Kenta Enomoto,

    STORES, Inc. Date: March 27, 2024 Introducing Pkl
  2. About Me 2 Kenta Enomoto STORES, Inc. Branded App Team

    iOS Engineer twitter.com/enomotok_ github.com/enomoto
  3. 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/
  4. Basic Syntax 4 name = "Swallow" job { title =

    "Sr. Nest Maker" company = "Nests R Us" yearsOfExperience = 2 } sample.pkl
  5. 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
  6. 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
  7. 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
  8. Use Cases 8 • Originally developed as a server technology

    • Generate Kubernetes manifest files
  9. 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.
  10. 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.)