Post

Replies

Boosts

Views

Activity

How does SwiftUI decide what default menu items to show on macOS?
I'm trying to write a simple image converter app. I want it to open any image file, and export that image as another type. I started with the multiplatform document app template in Xcode 15b2, and suppressed the New command with .commands { CommandGroup(replacing: CommandGroupPlacement.newItem) {} } I also changed the document readable types: static var readableContentTypes: [UTType] { [.image] } So far, so good. Then I tried modifying the document type declaration to be public.image, and removed the Imported UTI (reasoning that it’s a standard type and shouldn’t need to be redundantly declared, and how can I possibly list all the possible image filename extensions?), but I’m not at all sure I did that right. And somewhere in all that, I noticed that my File menu no longer has an Open command. Does SwiftUI look at the declared document type or imported UTIs to decide what the File menu should look like? UPDATE: Ah, suppressing the New menu also suppressed the Open/Open Recent menu items. That's frustrating.
0
0
607
Jun ’23
Xcode 15b2: Reference to 'Protocol' is ambiguous
I've got some old Objective-C code that up until Xcode 15 was compiling just fine. I recently spent time converting a lot of my project to Swift, which meant putting more stuff in the Bridging Header, but everything was fine. Till today. In file included from /Users/rmann/Projects/Personal/MyApp/repo/src/objc/MissionList/EventListCell.mm:18: In file included from /Users/rmann/Library/Developer/Xcode/DerivedData/MyApp-hkqhwvmmxqyxlkdlbpsbletzgerr/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/DerivedSources/MyApp-Swift.h:288: In file included from /Users/rmann/Projects/Personal/MyApp/repo/src/BridgingHeader.h:8: /Users/rmann/Projects/Personal/MyApp/repo/src/objc/HessianClasses/CWHessianArchiver.h:52:55: error: reference to 'Protocol' is ambiguous +(void)setClassName:(NSString*)className forProtocol:(Protocol*)aProtocol; ^ note: candidate found by name lookup is 'Protocol' note: candidate found by name lookup is 'Protocol' This is code that uses NSProxy and passes it an Objective-C protocol. The build transcript does not show the locations of the alleged declarations. If I use Shift-Command-O and type "Protocol", I get /Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/Protocol.h, which is unexpected, given that I'm running Xcode 15 beta 2. xcode-select -p gives /Applications/Xcode-beta.app/Contents/Developer. I call this a bug, as it compiles fine in Xcode 14.3, and if it should be an error, it should say why it's ambiguous. FB12434640
2
1
1.1k
Jun ’23
App runs fine, but preview complains executeFetchRequest:error: A fetch request must have an entity..
I'm migrating my app from Obj-C to Swift. It uses Core Data, and most of the entities are implemented in Obj-C. I just took a stab at converting one of my views to SwiftUI, and it runs correctly, but Preview crashes with executeFetchRequest:error: A fetch request must have an entity.. I've tried declaring the fetch request both with and without the entity: argument: @FetchRequest(entity: NewsItem.entity(), sortDescriptors: []) var newsItems : FetchedResults<NewsItem>
1
2
855
Jun ’23
Xcode has two kinds of source tabs. What are they?
Have you noticed that Xcode (15 for sure, I think 14 and earlier, too) has at least two kinds of source editor tabs. Some have the filename in regular text, some have it italicized. When the name is italicized, selecting another file in the navigator replaces the contents of that tab with that other file. When the filename is regular, a new tab is opened if you select a different file. When working with multiple related documents, I really dislike, in general, the browser model, wherein a windows contents are replaced by the thing you navigated to. But that's a whole separate rant. For now, I just want to know how and when Xcode decides to make one tab type or the other, and how can I control the behavior?
2
0
1.6k
Jun ’23
Xcode 15b4 not allowing TestFlight uploads?
I started building a new app with Xcode 15, and I uploaded a few builds to TestFlight with it. Now I'm trying with 15b4, and I'm getting: Invalid Toolchain. Your app was built with an unsupported SDK or version of Xcode. If you plan to submit this build to the App Store, make sure you are using the versions listed in https://help.apple.com/xcode/mac/current/#/devf16aefe3b or later. (ID: 0c544ce8-53ee-4122-b4a9-467a3d766349) Is this a bug? They've always allowed TestFlight builds with pre-release toolchans, havn't they? How else can you ensure your app is ready for the new OS version if you can't test changes to it?
0
0
630
Jul ’23
Getting UserDefaults notification changes in LSUIElement app
I have a regular app and an app with LSUIElement=YES. Both have Swift app lifecycle main entry points. Both have an app group ".com.company.app". Both can read and write prefs and see each other's values. But I can't for the life of me get changes from one app to notify the other. At first I tried NotificationCenter, but then learned (thanks to this thread) that you have to use KVO or Combine. I tried both. Both get the initial value, but never see subsequent changes. Combine seems to just wrap KVO, looking at the stack trace. I'm subscribing to updates like this: let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")! defaults .publisher(for: \.enabled) .handleEvents(receiveOutput: { enabled in print("Enabled is now: \(enabled)") }) .sink { _ in } .store(in: &subs) … extension UserDefaults { @objc var enabled: Bool { get { return bool(forKey: "Enabled") } set { set(newValue, forKey: "Enabled") } } } I'm writing to prefs like this: let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")! defaults.set(enabled, forKey: "Enabled") Am I missing something?
0
0
849
Nov ’23
Is there any way to prevent macOS from moving my app’s windows?
My app (AppKit, not SwiftUI) displays a small utility window. I can place it over the menu bar, or in the area beside the notch on my MacBook Pro (when it is a secondary screen), but if the screen goes to sleep and I wake it, macOS has moved the window off the menu bar or down out of the notch area. Is there any way to indicate a window should never be moved by the OS?
2
0
555
Nov ’23
Playing a specific rectangular ROI of a video?
Is there a way to play a specific rectangular region of interest of a video in an arbitrarily-sized view? Let's say I have a 1080p video but I'm only interested in a sub-region of the full frame. Is there a way to specify a source rect to be displayed in an arbitrary view (SwiftUI view, ideally), and have it play that in real time, without having to pre-render the cropped region? Update: I may have found a solution here: img DOT ly/blog/trim-and-crop-video-in-swift/ (Apple won't allow that URL for some dumb reason)
0
0
621
Dec ’23
Ignoring Command-Q in LSUIElement app (macOS, SwiftUI)?
I've got this LSUIElement app (no menu bar/dock icon). It puts up a window in certain circumstances to give the user control, but otherwise just runs in the background. Today I noticed that with its window frontmost, you can type Command-Q and it will quit. Is there a way to suppress that? I have explicit controls for quitting the app, but normally the user wants it to run in the background always, and I don't want it to be so easy to accidentally quit.
2
0
805
Dec ’23
When can I check AVPlayerItem’s status?
I’ve got some code that creates an AVPlayerItem from a URL, the creates an AVQueuePlayer from it. If I check the player item's status after that, it's still unknown. According to the docs, it'll remain unknown until it is associated with an AVPlayer, and then it "immediately begins enqueuing the item’s media and preparing it for playback." But checking the status right after that, I still get unknown, which tells me it’s not quite immediate. Is there any way to test if the player item will work immediately after creation? In this case, the problem is that my app doesn't have permission, due to it being a bookmark saved in a sandboxed app.
0
0
652
Dec ’23
How can I detect if my SwiftUI Window has been closed?
My macOS SwiftUI app has a single Window scene. .onAppear() is called when it is created, but if it is closed, .onDisappear() is not called. How can I detect when the window is closed? Note, I need to distinguish between closed and inactive or background. scenePhase is not updated for the window or any of its subviews when the window is deactivated. controlPhase is, however. Note that my app delegate implements: func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return false }
0
0
937
Dec ’23
configd is locking up my machine constantly and spamming logs
I've filed FB13497581 on this topic. But Ever since macOS 14 (or perhaps one of the releases that came after), my machine (M1 MacBook Pro) frequently locks up the UI. Sometimes it's so bad the mouse won't move. It only lasts a few seconds, but at its worst it happens every few seconds. It usually manifests as no text appearing as I type (which sucks, since I write code all day). I'm fairly certain configd is to blame. When this occurs, configd is using nearly 100% CPU, and spams logs with thousands of messages per second. Killing it does nothing. Rebooting might fix it for a bit, but it eventually comes back. I'm wondering if there’s some on-disk state I can blow away to start SystemConfiguration from scratch. I hate to do that in case someone from Apple asks me for files to analyze, but I feel like my FB is just going to languish. Meanwhile, this is rendering my machine unusable. Or if anyone knows how to interpret the log messages.
0
0
610
Jan ’24
My BGAppRefreshTask is never called
I get that iOS decides if it will call your task, but I let my app run overnight and it never once called a task that I schedule for about 20 min in the future. If I trigger it via the debugging options here it works fine, but never has the OS called me back.
Replies
0
Boosts
2
Views
763
Activity
Jun ’23
How does SwiftUI decide what default menu items to show on macOS?
I'm trying to write a simple image converter app. I want it to open any image file, and export that image as another type. I started with the multiplatform document app template in Xcode 15b2, and suppressed the New command with .commands { CommandGroup(replacing: CommandGroupPlacement.newItem) {} } I also changed the document readable types: static var readableContentTypes: [UTType] { [.image] } So far, so good. Then I tried modifying the document type declaration to be public.image, and removed the Imported UTI (reasoning that it’s a standard type and shouldn’t need to be redundantly declared, and how can I possibly list all the possible image filename extensions?), but I’m not at all sure I did that right. And somewhere in all that, I noticed that my File menu no longer has an Open command. Does SwiftUI look at the declared document type or imported UTIs to decide what the File menu should look like? UPDATE: Ah, suppressing the New menu also suppressed the Open/Open Recent menu items. That's frustrating.
Replies
0
Boosts
0
Views
607
Activity
Jun ’23
Xcode 15b2: Reference to 'Protocol' is ambiguous
I've got some old Objective-C code that up until Xcode 15 was compiling just fine. I recently spent time converting a lot of my project to Swift, which meant putting more stuff in the Bridging Header, but everything was fine. Till today. In file included from /Users/rmann/Projects/Personal/MyApp/repo/src/objc/MissionList/EventListCell.mm:18: In file included from /Users/rmann/Library/Developer/Xcode/DerivedData/MyApp-hkqhwvmmxqyxlkdlbpsbletzgerr/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/DerivedSources/MyApp-Swift.h:288: In file included from /Users/rmann/Projects/Personal/MyApp/repo/src/BridgingHeader.h:8: /Users/rmann/Projects/Personal/MyApp/repo/src/objc/HessianClasses/CWHessianArchiver.h:52:55: error: reference to 'Protocol' is ambiguous +(void)setClassName:(NSString*)className forProtocol:(Protocol*)aProtocol; ^ note: candidate found by name lookup is 'Protocol' note: candidate found by name lookup is 'Protocol' This is code that uses NSProxy and passes it an Objective-C protocol. The build transcript does not show the locations of the alleged declarations. If I use Shift-Command-O and type "Protocol", I get /Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/Protocol.h, which is unexpected, given that I'm running Xcode 15 beta 2. xcode-select -p gives /Applications/Xcode-beta.app/Contents/Developer. I call this a bug, as it compiles fine in Xcode 14.3, and if it should be an error, it should say why it's ambiguous. FB12434640
Replies
2
Boosts
1
Views
1.1k
Activity
Jun ’23
App runs fine, but preview complains executeFetchRequest:error: A fetch request must have an entity..
I'm migrating my app from Obj-C to Swift. It uses Core Data, and most of the entities are implemented in Obj-C. I just took a stab at converting one of my views to SwiftUI, and it runs correctly, but Preview crashes with executeFetchRequest:error: A fetch request must have an entity.. I've tried declaring the fetch request both with and without the entity: argument: @FetchRequest(entity: NewsItem.entity(), sortDescriptors: []) var newsItems : FetchedResults&lt;NewsItem&gt;
Replies
1
Boosts
2
Views
855
Activity
Jun ’23
Xcode has two kinds of source tabs. What are they?
Have you noticed that Xcode (15 for sure, I think 14 and earlier, too) has at least two kinds of source editor tabs. Some have the filename in regular text, some have it italicized. When the name is italicized, selecting another file in the navigator replaces the contents of that tab with that other file. When the filename is regular, a new tab is opened if you select a different file. When working with multiple related documents, I really dislike, in general, the browser model, wherein a windows contents are replaced by the thing you navigated to. But that's a whole separate rant. For now, I just want to know how and when Xcode decides to make one tab type or the other, and how can I control the behavior?
Replies
2
Boosts
0
Views
1.6k
Activity
Jun ’23
Xcode 15b4 not allowing TestFlight uploads?
I started building a new app with Xcode 15, and I uploaded a few builds to TestFlight with it. Now I'm trying with 15b4, and I'm getting: Invalid Toolchain. Your app was built with an unsupported SDK or version of Xcode. If you plan to submit this build to the App Store, make sure you are using the versions listed in https://help.apple.com/xcode/mac/current/#/devf16aefe3b or later. (ID: 0c544ce8-53ee-4122-b4a9-467a3d766349) Is this a bug? They've always allowed TestFlight builds with pre-release toolchans, havn't they? How else can you ensure your app is ready for the new OS version if you can't test changes to it?
Replies
0
Boosts
0
Views
630
Activity
Jul ’23
Getting UserDefaults notification changes in LSUIElement app
I have a regular app and an app with LSUIElement=YES. Both have Swift app lifecycle main entry points. Both have an app group ".com.company.app". Both can read and write prefs and see each other's values. But I can't for the life of me get changes from one app to notify the other. At first I tried NotificationCenter, but then learned (thanks to this thread) that you have to use KVO or Combine. I tried both. Both get the initial value, but never see subsequent changes. Combine seems to just wrap KVO, looking at the stack trace. I'm subscribing to updates like this: let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")! defaults .publisher(for: \.enabled) .handleEvents(receiveOutput: { enabled in print("Enabled is now: \(enabled)") }) .sink { _ in } .store(in: &subs) … extension UserDefaults { @objc var enabled: Bool { get { return bool(forKey: "Enabled") } set { set(newValue, forKey: "Enabled") } } } I'm writing to prefs like this: let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")! defaults.set(enabled, forKey: "Enabled") Am I missing something?
Replies
0
Boosts
0
Views
849
Activity
Nov ’23
Is there any way to prevent macOS from moving my app’s windows?
My app (AppKit, not SwiftUI) displays a small utility window. I can place it over the menu bar, or in the area beside the notch on my MacBook Pro (when it is a secondary screen), but if the screen goes to sleep and I wake it, macOS has moved the window off the menu bar or down out of the notch area. Is there any way to indicate a window should never be moved by the OS?
Replies
2
Boosts
0
Views
555
Activity
Nov ’23
Can an LSUIElement app decide to show a menu bar and then hide it again?
I would like for my app to have a menu bar under certain circumstances, but not most of the time. Is this possible?
Replies
0
Boosts
0
Views
340
Activity
Dec ’23
Playing a specific rectangular ROI of a video?
Is there a way to play a specific rectangular region of interest of a video in an arbitrarily-sized view? Let's say I have a 1080p video but I'm only interested in a sub-region of the full frame. Is there a way to specify a source rect to be displayed in an arbitrary view (SwiftUI view, ideally), and have it play that in real time, without having to pre-render the cropped region? Update: I may have found a solution here: img DOT ly/blog/trim-and-crop-video-in-swift/ (Apple won't allow that URL for some dumb reason)
Replies
0
Boosts
0
Views
621
Activity
Dec ’23
Ignoring Command-Q in LSUIElement app (macOS, SwiftUI)?
I've got this LSUIElement app (no menu bar/dock icon). It puts up a window in certain circumstances to give the user control, but otherwise just runs in the background. Today I noticed that with its window frontmost, you can type Command-Q and it will quit. Is there a way to suppress that? I have explicit controls for quitting the app, but normally the user wants it to run in the background always, and I don't want it to be so easy to accidentally quit.
Replies
2
Boosts
0
Views
805
Activity
Dec ’23
How do I view the contents of a Mac OS X Detached Code Signature?
I spent some time cleaning up my TCC data. During that I learned that some TCC info is cached in “Mac OS X Detached Code Signature” files. Is there a way to dump their contents suitable for human consumption? The codesign tool doesn’t seem to do it (or I can’t figure out how to invoke it).
Replies
0
Boosts
0
Views
509
Activity
Dec ’23
When can I check AVPlayerItem’s status?
I’ve got some code that creates an AVPlayerItem from a URL, the creates an AVQueuePlayer from it. If I check the player item's status after that, it's still unknown. According to the docs, it'll remain unknown until it is associated with an AVPlayer, and then it "immediately begins enqueuing the item’s media and preparing it for playback." But checking the status right after that, I still get unknown, which tells me it’s not quite immediate. Is there any way to test if the player item will work immediately after creation? In this case, the problem is that my app doesn't have permission, due to it being a bookmark saved in a sandboxed app.
Replies
0
Boosts
0
Views
652
Activity
Dec ’23
How can I detect if my SwiftUI Window has been closed?
My macOS SwiftUI app has a single Window scene. .onAppear() is called when it is created, but if it is closed, .onDisappear() is not called. How can I detect when the window is closed? Note, I need to distinguish between closed and inactive or background. scenePhase is not updated for the window or any of its subviews when the window is deactivated. controlPhase is, however. Note that my app delegate implements: func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return false }
Replies
0
Boosts
0
Views
937
Activity
Dec ’23
configd is locking up my machine constantly and spamming logs
I've filed FB13497581 on this topic. But Ever since macOS 14 (or perhaps one of the releases that came after), my machine (M1 MacBook Pro) frequently locks up the UI. Sometimes it's so bad the mouse won't move. It only lasts a few seconds, but at its worst it happens every few seconds. It usually manifests as no text appearing as I type (which sucks, since I write code all day). I'm fairly certain configd is to blame. When this occurs, configd is using nearly 100% CPU, and spams logs with thousands of messages per second. Killing it does nothing. Rebooting might fix it for a bit, but it eventually comes back. I'm wondering if there’s some on-disk state I can blow away to start SystemConfiguration from scratch. I hate to do that in case someone from Apple asks me for files to analyze, but I feel like my FB is just going to languish. Meanwhile, this is rendering my machine unusable. Or if anyone knows how to interpret the log messages.
Replies
0
Boosts
0
Views
610
Activity
Jan ’24