Core API Reference¶
The core module contains the foundational classes and functions for building Nib menu bar applications.
Entry Point¶
| Class / Function | Description |
|---|---|
| App | Main application class that manages the lifecycle of a menu bar app |
| run() | Recommended entry point for function-based apps |
UI Primitives¶
| Class / Function | Description |
|---|---|
| SFSymbol | Displays Apple SF Symbol icons in the menu bar or views |
| Menus | MenuItem, MenuDivider and view context menus |
| Ref | Handle to a view, for reaching it from handlers defined outside the tree |
State Management¶
| Class / Function | Description |
|---|---|
| State & Binding | Reactive state descriptor and two-way data binding for class-based apps |
| Settings | app.settings: preferences saved in UserDefaults, bindable to controls |
| UserDefaults | Low-level persistent key-value storage using macOS UserDefaults |
UI Configuration¶
| Class / Function | Description |
|---|---|
| SettingsWindow & SettingsTab | The preferences window, with a toolbar of tabs |
| FilePicker | Native macOS open/save file dialogs |
Diagnostics¶
| Class / Function | Description |
|---|---|
| Logging | nib.logger and LogLevel: the log shared with the Swift runtime |
Quick Example¶
import nib
def main(app: nib.App):
app.title = "My App"
app.icon = nib.SFSymbol("star.fill")
app.width = 300
app.height = 200
counter = nib.Text("0")
def increment():
counter.content = str(int(counter.content) + 1)
app.build(
nib.VStack(
controls=[counter, nib.Button("Add", on_click=increment)],
spacing=8,
padding=16,
)
)
nib.run(main)