Lots of random notes from building an app. See also SwiftUI notes.
Product > Archive
xcrun simctl delete unavailable
repo
accessgit@github.com:user/repo.git
var userDefaults = UserDefaults.standard
// set default values
userDefaults.register(
defaults: [
"enabled": true
]
)
// get value
UserDefaults.standard.bool(forKey: "enabled")
// set value
UserDefaults.standard.set(false, forKey: "enabled")
// AboutScreenController.swift
import Cocoa
class AboutScreenController: NSWindowController, NSWindowDelegate {
override func windowDidLoad() {
super.windowDidLoad()
}
}
// AppDelegate.swift
let windowController = AboutScreenController(
window: NSWindow(
contentRect: NSRect(x: NSScreen.main!.frame.width/2, y: NSScreen.main!.frame.height/2, width: 300, height: 200),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false
)
)
let aboutView = AboutView()
windowController.window?.delegate = windowController
windowController.window?.title = "TrackerZapper"
windowController.window?.contentView = NSHostingView(rootView: aboutView)
windowController.window?.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
// AboutView.swift
import SwiftUI
import Cocoa
struct AboutView: View {
var body: some View {
VStack(alignment: .center) {
Text("This is a window")
}
.frame(width: 200, alignment: .top)
.padding()
}
}
// default
NSApplication.shared.orderFrontStandardAboutPanel()
// with options
NSApplication.shared.orderFrontStandardAboutPanel(
options: [
NSApplication.AboutPanelOptionKey(rawValue: "Copyright"): "© 2021 Robb Knight"]
)