App Development
Lots of random notes from building an app. See also SwiftUI notes.
Make a Release in Xcode #
Product > Archive
Remove Unused Simulators from XCode #
xcrun simctl delete unavailable
Adding GitHub Package Dependency #
- Personal Access Token must have
repo
access - Use the SSH GitHub URL and not the HTTPS one, otherwise it will fail
git@github.com:user/repo.git
User Settings with UserDefaults #
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")
Open a SwiftUI View in Window #
// 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()
}
}
Show About Window #
// default
NSApplication.shared.orderFrontStandardAboutPanel()
// with options
NSApplication.shared.orderFrontStandardAboutPanel(
options: [
NSApplication.AboutPanelOptionKey(rawValue: "Copyright"): "© 2021 Robb Knight"]
)
Links #
- NSApplication.AboutPanelOptionKey - Keys to include in the options dictionary when displaying an About panel.
- LostMoa - Customise About Panel on macOS in SwiftUI
- Preparing Your App for Distribution | Apple Developer Documentation
- Add more information to default "About Panel" in Mac OSX with Credits.rtf
- martinlexow/Uberabout: “Uberabout” replaces the default “About” window in your macOS app with an aesthetically pleasing one.
- Anagh Sharma / macOS menu bar app with SwiftUI
- Create a macOS Menu Bar Application Using SwiftUI | by Aaron Wright | Medium
- Observe NSPasteboard — Swift 4. How to listen for clipboard changes | by Federico Vitale | Medium
- sindresorhus/Preferences: ⚙ Add a preferences window to your macOS app in minutes
- sindresorhus/LaunchAtLogin: Add “Launch at Login” functionality to your macOS app in seconds
- sindresorhus/KeyboardShortcuts: ⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes