run()¶
The recommended entry point for Nib applications. Creates an App instance, passes it to your main function for configuration, then starts the application event loop.
Signature¶
nib.run(main: Callable[[App], None], assets_dir: str | Path | None = None) -> None
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
main |
Callable[[App], None] |
none | A function that receives an App instance and configures it by setting properties and calling app.build() |
assets_dir |
str | Path | None |
None |
Path to the assets directory. When None, Nib auto-detects an assets/ folder relative to the script. Relative paths resolve from the main script directory |
Behavior¶
- If
assets_diris provided, callsApp.set_assets_dir(assets_dir). - Creates a new
App()instance. - Registers it as the current app (for
UserDefaultsandFilePickerto use by default). - Calls
main(app)so you can configure the app. - Calls
app.run()to connect to the Swift runtime and enter the event loop. - Cleans up when the app exits.
Examples¶
Basic usage¶
import nib
def main(app: nib.App):
app.title = "Hello"
app.icon = nib.SFSymbol("hand.wave")
app.width = 300
app.height = 200
app.build(
nib.Text("Hello, World!", font=nib.Font.TITLE, padding=20)
)
nib.run(main)
With custom assets directory¶
import nib
def main(app: nib.App):
app.title = "Gallery"
app.icon = nib.SFSymbol("photo")
app.width = 400
app.height = 300
# "logo.png" resolves to "my_assets/logo.png"
app.build(
nib.Image(src="logo.png", width=200, height=200)
)
nib.run(main, assets_dir="my_assets")
Related¶
- App: The application class configured inside the
mainfunction - SFSymbol: Icons used for
app.icon - Quick Start
- nib run: dev mode
- Architecture: process model