Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Last active March 24, 2026 23:36
Show Gist options
  • Select an option

  • Save chadbrewbaker/c95fc6abaf454bb6c690efe548715e18 to your computer and use it in GitHub Desktop.

Select an option

Save chadbrewbaker/c95fc6abaf454bb6c690efe548715e18 to your computer and use it in GitHub Desktop.
vibe swift UI app
llama-server \
  --model "/Volumes/Lexar/ollama_models/Qwen3.5-0.8B-Claude-4.6-Opus-Reasoning-Distilled.gguf" \
  --n-gpu-layers 99 \
  --ctx-size 24576 \
  --flash-attn on \
  --mlock \
  --port 8080
// swiftc -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk test.swift -o MyApp
// ./MyApp
import AppKit
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
app.run()
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
// We'll store a reference to this label to update it later
let statusLabel = NSTextField(labelWithString: "Status: Ready")
func applicationDidFinishLaunching(_ notification: Notification) {
// 1. Create the Window
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 450, height: 500),
styleMask: [.titled, .closable, .resizable, .miniaturizable],
backing: .buffered, defer: false)
window.center()
window.title = "macOS Widget Gallery"
// 2. Create a StackView (The Container)
// This handles layout automatically
let stackView = NSStackView()
stackView.orientation = .vertical
stackView.spacing = 15
stackView.edgeInsets = NSEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
// Make the stack view the main view of the window
window.contentView = stackView
// --- ADD WIDGETS ---
// 3. A Header Label
let header = NSTextField(labelWithString: "AppKit Widgets")
header.font = NSFont.boldSystemFont(ofSize: 22)
stackView.addArrangedSubview(header)
// 4. A Text Input Field
let textField = NSTextField()
textField.placeholderString = "Type a message here..."
stackView.addArrangedSubview(textField)
// 5. The Push Button
let button = NSButton(title: "Update Status Label", target: self, action: #selector(buttonClicked))
button.bezelStyle = .rounded
stackView.addArrangedSubview(button)
// 6. The Status Label (Display area)
statusLabel.textColor = .secondaryLabelColor
statusLabel.font = NSFont.systemFont(ofSize: 13)
stackView.addArrangedSubview(statusLabel)
// 7. A Checkbox
let checkbox = NSButton(checkboxWithTitle: "Enable Experimental Mode", target: self, action: #selector(checkboxToggled))
stackView.addArrangedSubview(checkbox)
// 8. A Slider with a Label
let sliderLabel = NSTextField(labelWithString: "Volume Control:")
stackView.addArrangedSubview(sliderLabel)
let slider = NSSlider(value: 50, minValue: 0, maxValue: 100, target: self, action: #selector(sliderMoved))
stackView.addArrangedSubview(slider)
// 9. A Dropdown Menu (PopUp Button)
let popup = NSPopUpButton(frame: .zero, pullsDown: false)
popup.addItems(withTitles: ["Light Mode", "Dark Mode", "System Default"])
stackView.addArrangedSubview(popup)
// 10. A Progress Indicator (Spinner)
let spinner = NSProgressIndicator()
spinner.style = .spinning
spinner.startAnimation(nil)
stackView.addArrangedSubview(spinner)
// Finalize window setup
window.makeKeyAndOrderFront(nil)
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
}
// --- ACTIONS ---
@objc func buttonClicked() {
statusLabel.stringValue = "Status: Action successful!"
statusLabel.textColor = .systemBlue
}
@objc func checkboxToggled(_ sender: NSButton) {
let state = sender.state == .on ? "Enabled" : "Disabled"
statusLabel.stringValue = "Status: Feature is now \(state)"
}
@objc func sliderMoved(_ sender: NSSlider) {
statusLabel.stringValue = "Status: Value set to \(Int(sender.doubleValue))"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment