I've got a Mac Document App using SwiftUI and SwiftData.
All is working well with the models editing, etc.
There's a feature I need to implement, and can't seem to make it work.
From the main window of the app, I need to be able to launch an auxilliary window containing a view-only representation of the model being edited. The required workflow is something like this:
Open a document (SwiftData)
Select a sub-model of the document
Launch the aux window to display the view of the model data (must be in a separate window, because it will be on a different physical display)
Continue making edits to the sub-model, as they are reflected in the other window
So, below is the closest I've been able to come, and it's still not working at all. What happens with this code:
Click on the "Present" button, the encounter-presentation Window opens, but never loads the data model or the view. It's just an empty window.
This is the spot in the main view where the auxiliary window will be launched:
@State
var presenting: Presentation? = nil
var presentingThisEncounter: Bool {
presenting?.encounter.id == encounter.id
}
@Environment(\.openWindow) var openWindow
...
if presentingThisEncounter {
Button(action: { presenting = nil }) {
Label("Stop", systemImage: "stop.fill")
.padding(.horizontal, 4)
}
.preference(key: PresentationPreferenceKey.self, value: presenting)
} else {
Button(action: {
presenting = Presentation(encounter: encounter, display: activeDisplay)
openWindow(id: "encounter-presentation")
}) {
Label("Present", systemImage: "play.fill")
.padding(.horizontal, 4)
}
.preference(key: PresentationPreferenceKey.self, value: nil)
}
Presentation is declared as:
class Presentation: Observable, Equatable {
Here's the contents of the App, where the DocumentGroup & model is instantiated, and the aux window is managed:
@State
var presentation: Presentation?
var body: some Scene {
DocumentGroup(editing: .encounterList, migrationPlan: EncounterListMigrationPlan.self) {
ContentView()
.onPreferenceChange(PresentationPreferenceKey.self) { self.presentation = $0 }
}
Window("Presentation", id: "encounter-presentation") {
VStack {
if let presentation = presentation {
PresentingView(presentation: presentation)
}
}
}
}
And the definition of PresentationPreferenceKey:
struct PresentationPreferenceKey: PreferenceKey {
static var defaultValue: Presentation?
static func reduce(value: inout Presentation?, nextValue: () -> Presentation?) {
value = nextValue()
}
}
Posts under macOS tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I have an object that is an NSRuleEditorDelegate for an NSRuleEditor whose nestingMode is NSRuleEditorNestingModeList. There are 8 different possible criteria. Each criterion is optional but at least 1 is required (ruleEditor.canRemoveAllRows = NO). Each criterion should only be added once. How can I limit adding a criterion for a row if it is already in the editor at a different row?
Thanks!
Hi, I need to import a trusted certificate to the system keychain without prompting the user. I’m importing the certificate with this command line: sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" <certificate> that running from the post install script of my PKG.
I'm running the PKG from my daemon service.
The certificate is imported to the keychain but it's not trusted. This is the error that i'm getting: sectrustsettingssettrustsettings: the authorization was denied since no user interaction was possible.
What is the right why for doing it?
Thanks
Hello,
macOS 15 and iOS 18 bring the iPhone Mirroring & the seamless drag and drop feature. However, Apple made these features unavailable in the EU. How can we as macOS developers in the EU test these features?
For more context, we develop a software product that is distributed worldwide and we have development and testing teams located in the EU. We would like to test how the iPhone Mirroring interacts with our product.
Thanks,
Robert
I am using NSMenuToolbarItem to show a drop-down menu in my NSToolbar. This works as expected when creating an NSMenu beforehand and assign it to the menu property of NSMenuToolbarItem.
However, my menu needs to be built dynamically when the user clicks the dropdown button. To do that, I am using NSMenuDelegate. When creating the menu in the menuNeedsUpdate of the delegate, the first menu item isn't shown to the user. Why?
Menu when using delegate:
Menu when pre-assigning menu:
I also cannot just add a placeholder menu item at the start of the NSMenuToolbarItem as all menu items do show in the overflow menu.
Example code:
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate, NSToolbarDelegate, NSMenuDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 400, height: 300),
styleMask: [.titled, .closable, .resizable],
backing: .buffered,
defer: false)
window.makeKeyAndOrderFront(nil)
let toolbar = NSToolbar(identifier: "MainToolbar")
toolbar.delegate = self
window.toolbar = toolbar
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [NSToolbarItem.Identifier("item1"), NSToolbarItem.Identifier("item2")]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [NSToolbarItem.Identifier("item1"), NSToolbarItem.Identifier("item2")]
}
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
willBeInsertedIntoToolbar: Bool) -> NSToolbarItem? {
let item = NSMenuToolbarItem(itemIdentifier: itemIdentifier)
if itemIdentifier == NSToolbarItem.Identifier("item1") {
let menu = NSMenu()
fillMenuWithItems(menu)
item.menu = menu
} else if itemIdentifier == NSToolbarItem.Identifier("item2") {
item.menu = NSMenu()
item.menu.delegate = self
}
return item
}
func menuNeedsUpdate(_ menu: NSMenu) {
menu.removeAllItems()
fillMenuWithItems(menu)
}
func fillMenuWithItems(_ menu: NSMenu) {
menu.addItem(NSMenuItem(title: "Option 1", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Option 2", action: nil, keyEquivalent: ""))
}
}
Hi all,
Before updating to iPadOS 18, the Table component in SwiftUI worked as expected, allowing multiple selections using the Shift key and mouse clicks.
However, after the update, this functionality no longer works on iPadOS 18 and macOS 15 (running with Catalyst).
Here’s a simplified version of the code:
@State var selections: Set<String> = []
var body: some View {
Table(devices, selection: $selections) {
// ...
}
}
Is there any workaround for this issue, or has anyone else encountered the same problem?
Thanks!
Hi everybody!
With latest updates on Ventura around 13.9.X, Sonoma 14.5 and upper, and most probably Sequoia, we notice a change on how to retrieve BSSID. We know Airport is discontinue, but also other commands are impacted by new security policies.
Now, to make any command work in the proper way we need to ask for Location Permission. But here is where we are finding some issues to make it compatible with the new requirements.
We have a web desktop app (Built with Electronjs) that use an mach-o executable (built on C++). This executable runs IOREG to retrieve the BSSID. One of the tries we did is to request the Location Permission on the parent/GUI app, but by doing this, IOREG was not able to retrieve the BSSID.
Then, we try to look for a way to make a little test only with our executable. But in the attempt to, we do not found a way to trigger the location permission request, either manually or by a command.
Is there a way to prompt the user from a terminal executable or the right way is to prompt from the GUI?
Do we need to stop using Mach-o executable in c++ and move to a native mach-o executable in swift to be able to prompt from it (This executable runs in the machine frequently, several times per minute)?
We are open to change the command if need it.
I am trying to fetch DHCP server identifiers of the current network. For IPv4 I am able to get this information using SCDynamicStoreCopyDHCPInfo and then using DHCPInfoGetOptionData fetching option 54.
I am trying to do the same thing for IPv6, in my scutil I do see DHCPv6 present. Is there any API present which fetches this information for v6 DHCP servers, or do I have to get this direct from scutil?
I was using a macOS 15.0 beta. and I tried to update to macOS 15.1. I clicked the update and entered my password but then it just stuck on loading forever. How can I fix that?
We have a developer-id application which includes a LaunchAgent, couple of LaunchDaemon and a system extension. We want to store our secure data in keychain that can read by any of our processes or at least by LaunchDaemons. We would also prefer for our data to not be visible to users, not be accessible to other processes and we did not want to use system keychain because of our prior experience where one of our app data on update corrupted the system keychain for one customer.
Therefore, we have decided to create our own keychain file and store our data there. However, we noticed that SecKeychainCreate and related file based keychain APIs are deprecated. This led me to below threads:
https://developer.apple.com/forums/thread/685546
https://developer.apple.com/forums/thread/712875
https://developer.apple.com/forums/thread/696431
And now I am confused. It is suggested that we should use data protection based keychain because file based keychains are on path to deprecation. However, it is also noted that data protection keychains do not work with LaunchDaemons. So which keychain is the right choice for our requirements?
Also,
One tricky aspect of this is that the SecItem API supports both keychain implementations
I do not see any option to use file based keychain using SecItem API. How can I create a new keychain file at a given path and add data in it using SecItem APIs? Can someone please elaborate on this with example?
Sticky key settings including activating it by tapping the shift key 5 times are disabled. However, the sticky key is activated automatically, so macOS behaves like the Shift Key is being pressed.
I updated to the latest OS version and logged into safe mode a few times but no help. I verified all the settings related to Sticky keys are disabled
Anyone faced this experience. How to stop activating the Sticky keys.
In macOS Sequoia, there are up to 3 locations where an end user can enable or disable a Network Extension.
In order of appearance in the System Settings.app application:
Network > Filters
General > Login Items & Extensions (1)
General > Login Items & Extensions > Network Extensions
a) it's quite difficult for an end user (and even a developer) to understand why there are 3 different locations and whether we are dealing with the same unique item or not. e.g. why would an end user have a clue about the difference between a Network Extension and a (Packet | Content) Filter?
b) it's not possible for an end user to figure out what the consequences of disabling an item in one of these 3 locations is going to be, because, in each case, the consequences appear to be different, undocumented or not detailed clearly in the UI. (2)
[Q] Is there a clear, complete and detailed documentation for Network Extensions UX controls in macOS Sequoia? For either end users or developers?
I could't find one when searching inside www.apple.com or developer.apple.com.
(1) not sure why a Network Extension also appears here as it's not a launchd daemon controlled by a 3rd party launchd plist. And not sure to understand why it's there since there's now the Network Extensions panel.
(2) it does not help that the output of the systemextensionsctl command line tool, in most cases, reports that the extension is still activated and enabled.
The Lightroom Classic app stops responding and freezes everytime I start the Tethered Capture with my Canon camera.
I have tried using multiple cables and even changed the camera models.
I have tried reinstalling the app and restarting my laptop.
I have given Full access of drive to Adobe and tried reconnecting the camera multiple times from different ports.
The app just stops working everytime it detects my camera.
I recently updated my laptop to macOS Sequoia 15.0
I am facing the problem after the update and it used to work perfectly before that.
Any suggestions or advice is appreciated.
I got this error while compiling to macOS app on flutter, can anyone help this problem ?
error : replacing existing signature, resource fork, Finder information, or similar detritus not allowed
I'm a font developer. In the development process, I will revise a font and overwrite the OTF file that is currently enabled (registered) with macOS.
If I then launch an app, it will immediately use the revised version of the font; while apps that are already loaded will continue to use the old version.
This suggests that each app is loading new and separate font data, rather than getting it from some existing cache in memory. Yet macOS does have a "font cache" of some sort.
Some apps, like TextEdit, seem to only load the fonts that they need to use. However, other apps, like Pages, load every enabled (registered) font on the OS!! (According to the Open Files list in Activity Monitor.)
Given that /System/Library/Fonts/ is 625 Mb, and we can't disable any of it, isn't that a lot of data to be repeating? How many fonts is too many fonts?
I can't find much documentation about the process.
I've got a bunch of Audio Units I've been developing over the last few months - in Xcode 14 based on the Audio Unit template that ships in Xcode.
The DSP heavy-lifting is all done in Rust libraries, which I build for Intel and Apple Silicon, merge using lipo and build XCFrameworks from. There are several of these - one with the DSP code, and several others used from the UI - a mix of SwiftUI and Cocoa.
Getting the integration of Rust, Objective C, C++ and Swift working and automated took a few weeks (my first foray into C++ since the 1990s), but has been solid, reliable and working well - everything loads in Logic Pro and Garage Band and works.
But now I'm attempting the (woefully underdocumented) process of making 13 audio unit projects able to be loaded in-process - which means moving all of the actual code into a Framework. And therein lies the problem:
None of the xcframeworks are modular, which leads to the dreaded "Include of non-modular header inside framework module". Imported directly into the app extension project with "Allow Non-modular Includes in Framework Modules" works fine - but in a framework this seems to be verboten.
So, the obvious solution would be to add a module map to each xcframework, and then, poof, they're modular.
BUT... due to a peculiar limitation of Xcode's build system I've spent days searching for a workaround for, it is only possible to have ONE xcframework containing a module.modulemap file in any project. More than that and xcodebuild will try to clobber them with each other and the build will fail. And there appears to be NO WAY to name the file anything other than module.modulemap inside an xcframework and have it be detected. So I cannot modularize my frameworks, because there is more than one of them.
How the heck does one work around this? A custom module map file somewhere (that the build should find and understand applies to four xcframeworks - how?)? Something else?
I've seen one dreadful workaround - https://medium.com/@florentmorin/integrating-swift-framework-with-non-modular-libraries-d18098049e18 - given that I'm generating a lot of the C and Objective C code for the audio in Rust, I suppose I could write a tool that parses the header files and generates Objective C code that imports each framework and declares one method for every single Rust call. But it seems to me there has to be a correct way to do this without jumping through such hoops.
Thoughts?
I am trying to open external/mounted storage in Finder. I simply just want to show the root directory. I have tried multiple things, none worked.
NSWorkspace.shared.open()
Does work when opening the user's disk (e.g. Macintosh HD), but when comes to any of the external storages a warning appears: "The application "ABC" does not have permission to open "Folder Name".
Now, the app ha been granted all permissions in the preferences (Full Disk Access + Files and Folders). Furthermore, I don't even need or care of accessing this directory from within my app. I want the Finder to open it.
I am using com.apple.security.files.user-selected.read-only and testing on MacOS: 14.6.1
Hi! After upgrading my Macbook Pro M1 Pro to MacOS Sequoia 15.0 when I run my python backend code i show in dock all python process as Exec Icon. Now work with backend so hard, because all my dock in this icons( How I can fix this? Support dont help me, because resinstall and e t c dont work for me.
I already updated my Iphone 11 to IOS 18 but still did not get the Iphone mirroring to connect to my macos sequoia
Hi, after upgrading to the latest versions of the OS, deep links to settings in my application stopped working.
For example:
UIApplication.shared.open(URL(string: "App-prefs:General"))
it opens settings but doesn't go to a category like on iOS 17. 😭